【问题标题】:How to combine jsbundle and code push if there are two condition?如果有两个条件,如何结合jsbundle和代码推送?
【发布时间】:2019-03-27 09:39:27
【问题描述】:

我已经在 XCode 上的 React Native 项目中设置了代码推送。

  #ifdef DEBUG
    jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
  #else
    jsCodeLocation = [CodePush bundleURL];
  #endif

现在我想生成jsbundle并在IOS设备上构建项目。

但是我发现jsCodeLocation是重复的。

#ifdef DEBUG
    jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
#else
    jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif

我很困惑如何结合 jsCodeLocation ?

我不熟悉 Objective-c。

【问题讨论】:

    标签: objective-c xcode react-native


    【解决方案1】:

    示例中提供:

    #import "AppDelegate.h"
    
    #import "RCTRootView.h"
    
    #import "CodePush.h"
    
    #import "RCTLog.h"
    
    @implementation AppDelegate
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
      RCTSetLogThreshold(RCTLogLevelInfo);
    
      NSURL *jsCodeLocation;
    
      jsCodeLocation = [CodePush bundleURL];
    
      RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                          moduleName:@"CODE_PUSH_TEST_APP_NAME"
                                                   initialProperties:nil
                                                       launchOptions:launchOptions];
    
      self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
      UIViewController *rootViewController = [[UIViewController alloc] init];
      rootViewController.view = rootView;
      self.window.rootViewController = rootViewController;
      [self.window makeKeyAndVisible];
      return YES;
    }
    
    @end
    

    https://github.com/Microsoft/react-native-code-push/blob/master/test/template/ios/TestCodePush/AppDelegate.m

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-02
    • 2019-04-05
    • 2021-09-21
    • 1970-01-01
    • 2020-07-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多