> For the complete documentation index, see [llms.txt](https://twins-bamboo.gitbook.io/react-native-note/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://twins-bamboo.gitbook.io/react-native-note/basic-ii/generating-signed-ipa-ios.md).

# Generating Signed IPA - iOS

{% hint style="danger" %}
&#x20;在打包前，請確認 開發/發布 憑證已搞定
{% endhint %}

### 打包步驟

1.導出js bundle(create a bundle)

在project(專案目錄)/ 下指令

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

\
2.設定Build Configuration為Release

```
 (Xcode選單)Product → Scheme → Edit Scheme (cmd + <)
 確保左側是選擇到 Run，如下圖
```

![](https://bambooooo.gitbooks.io/react-native/content/React%20Native/images/basic/generating/ipa1.png)

\
3.修改 AppDelegate.m 內的 jsCodeLocation

在AppDelegate.m內

註解下方這段

```
jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];
```

加上這段

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

如下圖

![](https://bambooooo.gitbooks.io/react-native/content/React%20Native/images/basic/generating/ipa2.png)

\
4.Archive 4-1. 將選擇機器的部分選成 Generic iOS Device（如下圖）

![](https://bambooooo.gitbooks.io/react-native/content/React%20Native/images/basic/generating/ipa4-1.png)

4-2. (Xcode選單）Product > Archive （我習慣會先Clean）

![](https://bambooooo.gitbooks.io/react-native/content/React%20Native/images/basic/generating/ipa3.png)

\
5.成功後會跳出視窗，如下圖

![](https://bambooooo.gitbooks.io/react-native/content/React%20Native/images/basic/generating/ipa4.png)

\
6.匯出 .ipa

可點擊上一步驟視窗內右上角的 Export 即可

\
ps.

* 新增udid後，修改證書，並且下載證書後 左鍵雙擊該證書 匯入Xcode。 之後新增的udid還是無法安裝！ 請依照以下步驟

  ```
  到證書(Mac)存放位於 /Users/XXXXX/Library/MobileDevice/Provisioning Profiles
  把證書刪光（會怕的話請先備份） >  左鍵雙擊證書 匯入Xcode > 重啟Xcode > 再次Archive即可
  ps.不確定是否匯入證書後重啟Xcode ，是否就可行
  ```
* 或者也可寫成下方這樣

  ```
  #ifdef DEBUG
  NSLog(@"........Debug For Developer(USB Connect).......");
  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
  #else
  NSLog(@"........Rlease For Archive.......");
  jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
  #endif
  ```

### &#x20;參考

* [How to build .IPA for React Native](https://stackoverflow.com/questions/35476349/how-to-build-ipa-for-react-native)
* [從壓出.ipa 到上架 完整圖文教學](https://www.jianshu.com/p/5aaba235a790)
* [iOS打包ipa發佈到蒲公英給測試人員用](https://www.jianshu.com/p/b8f8509f64fa)
* [React Native發布APP之打包iOS應用](https://github.com/crazycodeboy/RNStudyNotes/tree/master/React%20Native%E6%89%93%E5%8C%85%E5%8F%91%E5%B8%83App/React%20Native%E5%8F%91%E5%B8%83APP%E4%B9%8B%E6%89%93%E5%8C%85iOS%E5%BA%94%E7%94%A8)
