React Native開發之iOS打包ipa發布(親測可行)

我們可以用React Native提供的命令:
react-native bundle

Options:
--entry-file Path to the root JS file, either absolute or relative to JS root [required]
--platform Either "ios" or "android"
--transformer Specify a custom transformer to be used (absolute path) [default: "/Users/babytree-mbp13/projects/xcodeProjects/AwesomeProject/node_modules/react-native/packager/transformer.js"]
--dev If false, warnings are disabled and the bundle is minified [default: true]
--prepack If true, the output bundle will use the Prepack format. [default: false]
--bridge-config File name of a a JSON export of __fbBatchedBridgeConfig. Used by Prepack. Ex. ./bridgeconfig.json
--bundle-output File name where to store the resulting bundle, ex. /tmp/groups.bundle [required]
--bundle-encoding Encoding the bundle should be written in ([https://nodejs.org/api/buffer.html#buffer_buffer).](https://nodejs.org/api/buffer.html#buffer_buffer).) [default: "utf8"]
--sourcemap-output File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map
--assets-dest Directory name where to store assets referenced in the bundle
--verbose Enables logging [default: false]

其實用Xcode打開后可以開到main.js文件,不過是紅色狀態的,因為引用了但是并沒有這個文件存在,React Native這樣做的目的可能就是提示你還沒有生成離線數據的意思吧。??所以我們這里的bundle-output就選擇這個main.js,如果你想用別的名字,理論上是可以的,但是會提示找不到這個文件,你需要先生成一個空的文件就可以了。??--assets-dest選擇./ios就可以了,因為它會幫你在./ios下生成assets文件夾。

第一步

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

如果你是4.9版本以上使用一下命令:

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

準備就緒,開始打包。打包完后你就會看到main.js文件變為已有狀態了。??然后打開Appdelegate.m文件,修改:

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

jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];

然后再把assets文件夾添加到工程中,注意的是必須選擇Creat folder references否則運行時將會報錯,無法找到文件。


assets文件夾

第二步運行環境下的編譯設置(Debug/Release)

image.png

最后command+R運行,發現:程序崩潰了

出現這樣的原因是因為Build Phases中Copy Bundle Resources沒有添加我們剛才生成的main.js。

Copy Bundle Resources
再次command+R運行,跑起來了。
之后正常走Xcode打包發布流程就好了。
如果按照我這個步驟來還是不成功,給個??,私信我幫你!?

遇到錯誤1:

如果你打包IPA 安裝到真機上時遇到這個錯誤

dyld: Library not loaded: @rpath/RSKImageCropper.framework/RSKImageCropper
  Referenced from: /var/containers/Bundle/Application/04722779-7AB0-40C4-961E-4EED77C876A1/RichMedia1.app/RichMedia1
  Reason: image not found
image.png

在項目的General->Embedded Binaries中,將我們自定的framework 添加進去,如下圖:

image.png

錯誤二:

can't link with a main executable file for architecture armv7
解決:

在 target 下有個 test 工程,
找到 General,然后會看到一個 testing 
在 testing 下有個
 Allow testing Host Application APIs ,它默認是勾上的,把勾去掉,

歡迎大家加群討論
點擊鏈接加入群聊【ReactNative技術交流群3】:1085660877
相關文章:
1.React Native開發錯誤警告處理總結(已解決 !持續更新)
2.ReactNative 實現的文件上傳功能(實測可行!)
3.React Native開發總結之:開發技巧和調試技巧
4.React Native開發總結:一、開發環境配置
5.ReactNative之Android打包APK方法(趟坑過程)
6Android 調試錯誤總結(ReactNative開發)(持續更新)
7.ReactNative開發之真機測試
8React Native開發之iOS打包ipa發布(親測可行)

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容