React-native 打离线包(iOS)

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  就可以了

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容