React-native 打离线包(iOS)

2017-08-22  本文已影响438人  饭后的甜点_

1.react native 在本机可以访问到的情况下是可以在真机运行, 但是不在WIFI情况下真机是运行不了,所以我们这个时候需要打离线包.

facebooK 为我们提供的命令:  


react-native bundle --entry-file index.ios.js --bundle-output ./ios/bundle/index.ios.jsbundle --platform ios --assets-dest ./ios/bundle --dev false



2.将项目工程iOS目录下的assets 拖入xcode项目中 注意要用Create folder references去添加


asset 加入项目中

最后在APPDelegate.m中将代码修改

NSURL *jsCodeLocation;

// jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];

jsCodeLocation = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"index.ios.jsbundle" ofType:nil]];

RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation

moduleName:@"RNBundleDemo"  initialProperties:nil  launchOptions:launchOptions];

最后command +  R  就可以了

上一篇 下一篇

猜你喜欢

热点阅读