ios原生项目展示reactnavtive界面(RN学习二)

基础:ios工程集成好reactnactive(可参考https://www.jianshu.com/p/23364db81a08),不足之处请指出

本文介绍在ViewController中加载reactnative界面,其实很简单,主要代码如下:

#import (先导入)

 NSString*urlStr =@"http://127.0.0.1:8081/index.bundle?platform=ios&dev=true";//index为要展示的rn界面,很多老项目为index.ios.js,那么此时这里就是index.ios

    NSURL*jsCodeLocation = [NSURLURLWithString:urlStr];

    RCTRootView *rootView = [[RCTRootView alloc]initWithBundleURL:jsCodeLocation moduleName:@"rntest" initialProperties:nil launchOptions:nil]; rootView.backgroundColor= [[UIColor alloc]initWithRed:1.0f green:1.0f blue:1.0f alpha:1.0f];

    rootView.frame= [[UIScreen mainScreen]bounds];

    [self.viewaddSubview:rootView];

若想在开发模式下运行程序,请先在工程根目录执行npm start

你可能感兴趣的:(ios原生项目展示reactnavtive界面(RN学习二))