發表於 程式分享

ionic FCM for iOS開發版上架流程

1.申請Apple Developer Account
登入https://developer.apple.com/
需要登記Apple Developer Program,年費為99美元,要擁有付費開發者帳戶,才可使用其推播功能。

2.於Mac機器產生 CSR 檔
開啟鑰匙圈存取: 開啟Spotlight後,輸入keychain Access.
=> 於menu選單點選Keychain Access
=> 點選 “Certificate Assistant"(憑證輔助程式) 選單
=> 點選 “Request a Certificate From a Certificate Authority…"(從憑證授權要求憑證…)
=> 出現 “Certificate Assistant" 視窗
=> 填上自己的 Email 及 名字 並選 “Saved to Disk" 後,
再點選 “Continue" Button產生CSR檔(檔名為CertificateSigningRequest.certSigningRequest)

3.設定Apple Developer Account
點選左方選單 “Certificates, IDs & Profiles"
=> 點選左方選單 “Identifiers"
=> 點選 “Identifiers" 選單下的 “App IDs" 選單
=> 點選 “iOS App IDs" 頁面右上角 + 按鈕
=> 進入 “Register iOS App ID"頁面,填上如下資料
1) App ID Description—?Name:
填入App名稱(Ex.QRCode測試專案App).
2) App ID Suffix?—?Explicit App ID?—?Bundle ID:
即App的Bundle Identifier(如:com.xxx.test.qrcodedemo).
=> 於App Services內,點選 “Push Notification"
=> 頁面連結至 “Confirm your App ID" 頁面, 請按 “Register"
=> 於 “iOS App IDs" 頁面,點選剛建立的App ID,
看到Application Services的功能選項,請點選最下方的 “Edit" 按鈕
=> 於 “iOS App Settings" 頁面,點選 “Push Notifications"選項
=> 建立 “Client SSL Certificate"以使用 Firebase Server 連接到Apple Push Notification Services.
因為目前是在開發階段,故於Development SSL Certificate內 點選”Create Certificate…”按鈕.

4.上傳 CSR 檔 以 下載 iOS憑證 for Push Services
接續第3項操作於 “Add iOS Certificate" 頁面
=> 點選 “Continue" 按鈕
=> 點選 “Choose file…", 上傳第2項產生的CSR檔, 按 “Open"按鈕.
=> 按 “Continue" 按鈕, 顯示 “Your Cerificate is ready" 頁面
=> 按 “Download" 按鈕下載 iOS憑證 for Push Services (檔名預設應該是aps_development.cer)

5.準備 APNs(Apple Push Notifications) 憑證 (p12檔)
點選兩下第5項產生的認證檔案(aps_development.cer)以加入到鑰匙圈存取(Keychain Access).
=> 開啟 “鑰匙圈存取頁面", 於 “我的憑證"(My Certificates), 可查詢剛加入的認證檔,
應為:Apple Development IOS Push Services:
=> 認證檔檔名左邊有一個展開箭頭,
點選展開後,有一個屬性(應為第2項輸入的名字),
點選後,按右鍵,再按 “export" Button.
=> “是否要儲存你的private key為p12檔" 確認視窗跳出
=> 按 “儲存" 按鈕後
=> 若想保護你輸出後的認證, 可輸入密碼來保護它,
再點選 “OK" 按鈕,即產生p12檔

5.申請 FCM 帳號
登入 https://firebase.google.com/ 進入控制台(console)
=> 點選 “CREATE NEW PROJECT" 按鈕
=> 設定 Project Name 及 Country region
=> 進入 Project, 點選 “Add Firebase to your iOS" 按鈕,
輸入你的iOS bundle ID (需與XCode Project同), 再點選 “ADD APP" 按鈕
=> 下載 GoogleService-Info.plist 檔
=> 點選 “CONTINUE" 按鈕, 現在請先忽略它, 按下 “CONTINUE" 按鈕
=> 點選 “Finish" 按鈕, 顯示 iOS App Firebase 頁面.
Ref.申請FCM推播帳號

6.Firebase 推播設定
iOS App Firebase 頁面
=> 頁面左上角Setting icon, 點選 settings icon, 再點選 Project settings
=> 選取頁籤 “Cloud Messaging"
=> 點選 “Upload Certificate" 按鈕
=> 出現 “Upload your Development APNs certificate" 頁面,
點選 “BROWSE" 上傳第5項產生之p12檔, 若先前有設定密碼也請一併輸入
=> 顯示結果: Development APNs certificate 已存入Cloud Messaging setting內

7.Firebase推播功能的Demo App
1) 我是用ionic開發, FCM於ionic引用方式請參考:           https://ionicframework.com/docs/native/fcm/.
2) build成上架程式有遇的問題處理方式: 可參考ionic 2 (from Visual Studio) build iphone/ipad遇到問題
上架的方式請參考iPhone/iPad開發實機測試及上架練習筆記iTunes Connect通知外部人員測試 App- TestFlight初體驗
3) 此次上傳程式至iTunes收到apple通知信有如下3問題


Dear developer,
We have discovered one or more issues with your recent delivery for "[Project Name]". To process your delivery, the following issues must be corrected: 
Missing Info.plist key - This app attempts to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSCameraUsageDescription key with a string value explaining to the user how the app uses this data. 
Though you are not required to fix the following issues, we wanted to make you aware of them:
Missing App Store Icon - iOS Apps must include a 1024x1024px App Store Icon in PNG format. Without providing the icon in the Asset Catalog or via iTunes Connect, apps cannot be submitted for App Review or Beta App Review. Refer to https://developer.apple.com/ios/human-interface-guidelines/icons-and-images/app-icon/ for more information. 
Missing Push Notification Entitlement - Your app appears to register with the Apple Push Notification service, but the app signature's entitlements do not include the "aps-environment" entitlement. If your app uses the Apple Push Notification service, make sure your App ID is enabled for Push Notification in the Provisioning Portal, and resubmit after signing your app with a Distribution provisioning profile that includes the "aps-environment" entitlement. Xcode 8 does not automatically copy the aps-environment entitlement from provisioning profiles at build time. This behavior is intentional. To use this entitlement, either enable Push Notifications in the project editor's Capabilities pane, or manually add the entitlement to your entitlements file. For more information, see https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/HandlingRemoteNotifications.html#//apple_ref/doc/uid/TP40008194-CH6-SW1. 
Once the required corrections have been made, you can then redeliver the corrected binary. 
Regards,
The App Store team

4) Missing App Store Icon 解法說明
先直接於Xcode內調整:
先產生1張1024×1024 icon (png檔)
=> 於Xcode project 選取 Images.xcassets,
=> 點選 AppIcon 項次, 將1024×1024 icon (png檔)拉入2處 App Store iOS 1024pt

有找到 ionic 專案內應該是於config.xml 的
      新增
      及將1024×1024 icon (png檔)放入對應目錄 => 此項還待驗證中

5) Missing Info.plist key 解法說明
      因為顯示的是 NSCameraUsageDescription key with a string value explaining to the user how the app uses this data,
      即因有使用攝影機功能, 故需加註說明於
      先直接於Xcode plist內調整: (info.plist加上Privacy Camera Usage Description)
      Info頁
      => Custom iOS Target Properties
      => 新增如下說明 (說明也可用中文字)

Key    :  Privacy - Camera Usage Description   
Value  :  $(PRODUCT_NAME) camera use

      Ref.https://stackoverflow.com/questions/39465687/nscamerausagedescription-in-ios-10-0-runtime-crash
iOS 10 存取使用者私密資料都要加上 usage description

6) Missing Push Notification Entitlement 解法說明
a.GoogleService-Info.plist需在XCode project folder內,
      之前遇到ionic build後會變空檔, 處理方式可參考ionic 2 (from Visual Studio) build iphone/ipad遇到問題.
b.在Xcode project navigation內找到Project (info.plist),
      選取 Target => Capabilities => 開啟 Push Notification (狀態需為 ON)

Ref.Missing Push Notification Entitlement warning
IOS上架提交審核遇到Missing Push Notification Entitlement的問題
Generate an iOS Push Certificate

8.測試Firebase推播功能
Firebase Console, 選擇Firebase Project, 於左側選單選擇 Notification,
      => 於 Notification 頁面 點選 “SEND YOUR FIRST MESSAGE" 按鈕
      => 可開始輸入選項進行測試

Ref.Push Notification教學:如何使用Firebase在iOS實現推播功能
Firebase Cloud Messaging (FCM)