美文网首页
React Native 集成到现有的应用中

React Native 集成到现有的应用中

作者: Scott丶Wang | 来源:发表于2017-03-27 15:56 被阅读132次

注意点1

如何在不同的环境下正确运行,DEBUG环境下,在模拟器以及真机上运行;发布环境下,热更新。

1)DEBUG环境下,

在模拟器以及真机上运行注意点:Mac 与 iPhone需要在同一WIFI环境下,开启服务器,获取你的Mac ip地址

2)Release环境下

不懂的需要自己在ReactNative中文网上查找,然后正确配置好。

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    NSURL *jsCodeLocation;
#if DEBUG
    #if TARGET_IPHONE_SIMULATOR
        jsCodeLocation = [NSURL URLWithString:@"http://你的Mac ip地址:8081/index.ios.bundle?platform=ios&dev=true"];
    #else
        jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];
    #endif
#else
    jsCodeLocation = [RCTHotUpdate bundleURL];
#endif
    RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                        moduleName:@"YouApplicationName"
                                                 initialProperties:nil
                                                     launchOptions:nil];
    self.view = rootView;
}

注意点2

采用cocoapods安装React Native的时候

platform :ios, '8.0'
target 'YouApplicationName' do
  pod 'React', :path => ‘../node_modules/react-native', :subspecs => [
      'Core',
    'ART',
    'RCTActionSheet',
    'RCTAdSupport',
    'RCTGeolocation',
    'RCTImage',
    'RCTNetwork',
    'RCTPushNotification',
    'RCTSettings',
    'RCTText',
    'RCTVibration',
    'RCTWebSocket',
    'RCTLinkingIOS',
       # 其他你需要的模块,为了演示这里列举了所有的模块
  ]
  # 如果你的RN版本 >= 0.42.0,请加入下面这行
  pod "Yoga", :path => “../node_modules/react-native/ReactCommon/yoga"
end

相关文章

网友评论

      本文标题:React Native 集成到现有的应用中

      本文链接:https://www.haomeiwen.com/subject/fnerottx.html