這是我在2023第十五屆 iThome 鐵人賽發表的系列文章。https://ithelp.ithome.com.tw/users/20136637/ironman/6408
前言
要使用 TestFlight 測試應用以及上架 App Store 都需要加入 Apple developer program,個人帳號每年需支付 $99 USD,如果是企業帳號則是每年 $299 USD。
Apple 是每年都要付錢,Google 是只要付一次,要看清楚喔
上架應用到 App Store 之前需要了解的
上架 iOS 應用到 App Store 需要設置 Certificate, Identifier, Device 和 Provisionging Profile,先大致了解這幾個東西是什麼、有什麼用再繼續比較不容易迷路。
Certificate
開發者憑證,要有憑證才能上傳應用至 App Store Connect。如果 Certificate 過期,已上架的應用不會受到影響,但要送審新的應用或者更新應用就得建立新的 Certificate。
新增 Certificate 有兩種方式(擇一即可):
- 在 XCode – Settings – Accounts – Manage Certificates – + Apple Development 中自動生成
- 在電腦中搜索 keychain – 憑證輔助程式 – 從憑證授權要求憑證,輸入 Apple developer 帳號的 Email,並選擇儲存到磁碟,就會產生 .csr 檔案
接著在 Apple developer 的 Certificates, Identifiers & Profiles 新增 Certificate 並上傳 .csr 檔案
在 keychain(鑰匙圈存取) – 登入 – 我的憑證 中可以確認 certificate
- 如果要在其他設備上使用相同的憑證,需要將憑證輸出成 .p12 檔,再匯入到另一個設備上(對著憑證按右鍵就可以輸出)
- 輸出時會要求你設置 .p12 的密碼,這個密碼很重要,記得保存起來。
Identifier
APP 簽署識別,用於建立 App 的 bundle ID 以及設置 APP 會使用到的 capabilities 和 services。
在 Apple developer 的 Certificates, Identifiers & Profiles 中新增。
Bundle ID 和 Android 的 package 類似
- 普遍格式為
com.example.myapp
(反向的網域,example 通常為公司名稱或組織名稱) - 只能包含字母、數字和
-
- 最大長度為 255 字符
- 必須是全 App Store 唯一的

Device
註冊裝置,可以用該裝置來測試應用。
會需要裝置的 UDID,可以打開 XCode – Window – Devices and Simulators 找到裝置

這邊的 Identifier 就是 UDID

Provisionging Profile
APP 佈建設定,將 Certificate, Identifier 和 Device 關聯在一起。


在 XCODE 中新增 APPLE ID
當前面四大關卡都設置完成之後,在 XCode – Settings – Accounts – + Apple ID 中添加 Apple ID,選擇 Team,點擊「Download Manual Profiles」就可以將 profile 直接下載到 mac 中。

設置 Signing
Signing & Capabilities 找到 Signing:
- 選擇 Team
- 輸入 Bundle Identifier

Bundle Identifier 設置成功的話下方 iOS 區塊會顯示 Provisioning Profile 以及 Signing Certificate,如果沒設置完全就會顯示錯誤。
Expo
如果使用 Expo 開發,需要在 Project credentials 添加 Bundle Identifier

有四個必填項目
- Bundle Identifier
- Distribution type
- Distribution certificate
- Provisioning profile



上傳 certificate 的 .p12 檔以及密碼。
獲取 .p12 的方式:
- 在 Apple developer 的 Certificates, Identifiers & Profiles – Certificate 下載
- 在本機 keychain 輸出 .p12

接著上傳 Provisioning Profile,一樣是在 Certificates, Identifiers & Profiles 下載

接下來的 Push Key、App Store Connect API Key 都可以 Skip,除非你需要 push notifications 或者使用 eas submit 上傳應用到 App Store Connect。


Push Key、App Store Connect API Key 需要的資料獲得方式請參考 expo 官方的教程
關於 EAS Submit 的設置也請參考官方文檔
測試 release 應用
Product – Scheme – Edit Scheme 將 Run 的 Build Configuration 改為 Release


Product -> Build 或直接使用指令 npm run ios -- --mode="Release"
測試 release 應用是否能正常運行:

設置應用版本
在 General – Identity 可以設置應用的 version 和 build,不能上傳重複的 version+build 到 App Store Connect
Version
- App Store 應用版本號
- 即 Info.plist 中的
CFBundleShortVersionString
- 版本重複或者格式錯誤一樣可以 build,但無法上傳至 App Store Connect
Build
- 內部版本號,不會公開
- 即 Info.plist 中的
CFBundleVersion
- 相同 Version 不能有相同的內部版本號,但不同的 Version 可以(如:Version: 1.0.0, Build: 1; Version: 1.0.1, Build: 1)

應用上架前的準備工作: https://ithelp.ithome.com.tw/articles/10329076
在 App Store Connect 新建 APP
App Store Connect: https://appstoreconnect.apple.com/
新建 APP 的時候會需要選擇應用使用的平台、名稱、主要語系、Bundle ID 和 SKU
- Bundle ID: 在提交首個建置版本後便無法再更改
- SKU: App 獨一無二的 ID,不會顯示在 App Store 上

發送應用到 App Store Connect
將裝置設為 Any iOS Device (arm64)

Product -> Archive -> Distribute APP


選擇 Distribution:
- App Store Connect:可以將應用發佈到 App Store,但需要經過蘋果審查,而且應用需要符合蘋果的規定政策。
- Add Hoc:主要用於內部測試,通常是給開發團隊或合作夥伴提前測試應用。不需要通過蘋果審核,但每年最多只能註冊 100 台設備。
- Enterprise:主要用於企業內部,應用不會在 App Store 上公開,且不需要通過蘋果審核,但需要企業帳號(每年 $299 USD)。
- Development:主要用於開發和測試,不需要蘋果審核,方便開發過程中的快速迭代。每個 developer account 有一定數量的設備限制。
這邊我們選擇 App Store Connect 即可




確認應用信息:


在 TestFlight 上測試應用
將應用推上 App Store Connect 之後在 TestFlight 這邊會出現對應的建置版本
- 推上去需要等個幾分鐘才會出現,通常不會太久

點擊設置出口合規資訊後,等待大約 5-10 分鐘就可以測試了。

要用 TestFlight 測試需要先建立內部群組:

接著在內部測試組別中的下方「測試人員」旁邊按「+」


受邀測試的人員信箱會收到邀請信,裡面會有應用 TestFlight 的連結,點進去會看到應用的兌換碼:
- 兌換碼使用過後就無法再次兌換
- 登入的 Apple ID 和受邀請的 Apple ID 不一樣也可以兌換,只要有邀請碼就好了

打開 TestFlight 輸入兌換碼之後就可以測試應用了。

上架 App Store
要上架應用到 App Store 需要填寫應用資料,基本的包括:
- 應用在指定尺寸(型號)的 iPhone, iPad 上的截圖
- 預設是:iPhone 6.7吋、6.5吋、5.5吋,iPad Pro 第六代、第二代 12.9吋
- 各尺寸的大小請參考官方文檔:https://developer.apple.com/help/app-store-connect/reference/screenshot-specifications
- 截圖必須是 JPG 或 PNG 格式,且必須採用 RGB 色彩空間。App 預覽必須是 M4V、MP4 或 MOV 格式,且不可超過 500 MB。
- 測試用的帳號(如果應用需要登入才能使用的話)
- 建置版本
- 描述、聯絡人資訊、類別、分級、語言、定價…等
如果應用中有涉及付費內容的話需要另外設置。
全部準備完畢之後點擊「新增以供審查」即可送交蘋果審查。

首次提交會需要比較久,但如果審核不通過的話通常很快就會收到通知 XD