React-Native 打包iOS HOC

1,002 阅读1分钟

打包步骤如下: 1.打开terminal终端->cd 项目更目录 2.项目根目录/ios/手动创建(bundle)文件 3.在终端输入如下命令:

(index.ios.jsbundle可以自行修改)

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

参考地址: https://www.jianshu.com/p/5a71437c3678

完成后如下图:

4.在xcode项目中引入bundle文件 1、将assets 和 index.ios.jsbundl 文件引入到xcode工.如下图:

注意: assets 目录导入工程中时,要选择 Create folder references,因为这是图片素材

5.修改Appdelegate中的配置代码
   
    #if DEBUG
        jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
    #else
         jsCodeLocation = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"index.ios.jsbundle" ofType:nil]];
    #endif

6、选择Xcode设置导航,配置证书;如图:

hoc证书参考:www.jb51.net/article/101…

注意

build 选择Edit Scheme时选择debug/release版本进行测试打包

遇到的问题: 1.

解决方案:Xcode->file->WorkSpace settings...在弹出框中选择Legacy Build System,最后选择Done即可

2、错误2.

解决方案如下: 将项目/ios/build文件夹删除即可

自此发布测试包,正式包,只需修改证书就好。