基礎(chǔ):ios工程集成好reactnactive(可參考http://www.reibang.com/p/23364db81a08),不足之處請指出
本文介紹在ViewController中加載reactnative界面,其實很簡單,主要代碼如下:
#import <React/RCTRootView.h>(先導(dǎo)入)
?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];
若想在開發(fā)模式下運行程序禁谦,請先在工程根目錄執(zhí)行npm start