注冊成為開發者
登錄蘋果開發者中心,點擊Accounts,在這里需要你填寫你的Appple ID進行登錄,如果沒有,點擊這里申請一個,填寫信息就成,這里就不再贅述。申請完成之后,使用申請的AppID進行登錄。
進入主頁之后,然后點擊Join the Apple Developer Program進行開發者賬號申請。點擊Enroll
這里有幾個點需要說明下:
-
蘋果的開發者賬號主要分為個人、組織(公司/企業)、教育機構
類型 費用 是否支持App Store上架 最大支持uuid數量 開發人數 備注 個人(Individual) $99 支持 100 1 可以轉為公司賬號 組織(Organization) $99 支持 100 多人 申請時需要填寫公司的鄧白氏編碼(DUNS Number) 企業程序(Enterprise Program) $299 不支持 不限 多人 申請時需要填寫公司的鄧白氏編碼(DUNS Number)
點擊Start Your Enrollment,目前申請開發者賬號,需要在AppStore下載 Apple Developer然后進行申請。
點擊現在注冊
,按照程序一步步填寫信息,最后點擊訂閱即可。
一般情況下,訂閱成功需要兩天時間,請耐心等待。
Certificates、p12以及provisioning Profiles
小白(在沒有查閱資料之前我也是😺)最初看到這三個名詞的第一反應可能是:證書我聽過,但是其他兩個是個什么東西,我倒不太清楚。
這三個文件是做什么的,暫時可以不用了解,現在只需要記住的是:在ios打包的時候需要用到。下面是一個比較完整的ios打包流程圖,可以提前幫助理解。
注:以上圖片來自於https://reactorapps.io/blog/ios-certificate-guide/
下面,我就用小白的視角來講講我是怎么認識這三個東西的。
證書(Certificates)
證書是由公 證 處或認證機關開具的證明資格或權力的證件,它是表明(或幫助斷定)事理的一個憑證。證件或憑證的尾部通常會烙印公章。
A certificate is a document that Apple issues to you. This certificate states that you are a trusted developer and that you are in fact, who you claim to be, rather than someone else posing as you.
證書的最主要功效就是證明你是誰以及你是否合法,就像一般開一家餐館一樣,你需要拿到一個營業執照,顧客也就認這個,這里申請的證書是蘋果公司頒發的。
那么怎么申請證書?
網上關於這方面的資料很多,這里不在贅述,可以查看手把手教你搞定ios的證書申請
-
生成Certificate Signing Request (CSR),填寫相關的信息后,保存到本地,會生成一個以
.certSigningRequest
結尾的CSR文件A CSR or Certificate Signing request is a block of encoded text that is given to a Certificate Authority when applying for a certificate.
- 在蘋果開發者中心中創建一個
Certificate
- 上傳在本地生成的CSR文件,下載證書
- CSR文件中包含一個
public key
,這個key也會包含在生成的證書中,同時還會在keychian
中生成一個private key
非對稱加密(Asymmetric cryptography)
Public-key cryptography, or asymmetric cryptography, is a cryptographic system that uses pairs of keys: public keys, which may be disseminated widely, and private keys,which are known only to the owner.
一個簡單的例子,圖片來自於https://en.wikipedia.org/wiki/Public-key_cryptography#Examples
同樣還是以開餐館的例子來講,當餐館越做越大,需要采購一大批原材料的時候,這時候就需要請示老板了,老板拿了采購單審查了之后,覺得沒啥問題,然后就會在采購單上簽名。采購員拿着有老板簽名的采購單,就去采購貨物去了。這里面有幾個關鍵點:
- 采購員只有在見到有老板簽名的單子才認為是老板下達的命令
- 任何偽造的、模仿的或者不是老板簽字的一律不具有效益
- 采購員在心中已經形成了一個老板簽名的樣板
其實這就是一個非對稱加密的例子,老板的簽名樣板其實就是一個公鑰(public key),餐館中的任何人都可以知道,而真實的老板簽名字樣即是私鑰(private key),這個簽名手法是老板獨有的。只有當經過簽名之后的采購清單和簽名樣板進行匹配(這里的匹配其實就是使用公鑰解密簽名之后的內容)之后,才會認為這個采購單具有效益。
那么同理,怎么認為App是你獨有的呢?就需要在發布的時候,對App進行私鑰加密,即是數字簽名
P12
P12文件中包含了你的證書(包含了你的公鑰)和你的私鑰。
當你的App需要簽名的時候,P12文件會一分為二。私鑰用來做數字簽名,公鑰會打包進入你的app中,這樣用戶就可以根據app中的公鑰來驗證你的app的真實性。
獲取p12文件
我們可以從下載下來的證書中導出p12文件。
選擇Export
,其間會要求你輸入密碼。
描述文件(provisioning Profiles)
簡單來說,描述文件其實就是一份清單,包含了App中的一些必要信息,主要包括
- AppId,即為Bundle identifier,唯一,通常以
reverse domain name
的形式出現,例如org.reactjs.native.example.TryWithReactNative
- 證書(Development Certificates),打包App時生成的證書
- Device UUid,設備的編號,規定了打出來的這個包只能由哪些設備使用(Distrubtion Provisioning Profiles中不包含Device id)
Provisioning Profiles分為兩種,一種用於Development
模式,可以供多人測試使用;一種用於Distribution
模式,用於上傳App Store。兩種文件中的區別是,Distribution Provisioning Profiles中不包含device id。
注:以上圖片來自於https://medium.com/@jadhavrajashri49/provisioning-profile-67fad1907694
怎么創建Provisioning Profiles?
關於怎么創建,以及創建不同模式下的Provisioning Profiles,可以參看證書(Certificate)與描述文件(Provisioning Profiles),這里不再贅述。
證書創建完成后需要把描述文件手動下載到本機
找到你要使用的描述文件(開發者、發布)單擊后顯示如下內容,單擊“Download”后保存到 “/Users/rongshenglai/Library/MobileDevice/Provisioning Profiles” 目錄中注意每個人的個人目錄不同根據情況修改。
下載的文件名類似“XXXX.mobileprovision” 前邊的XXXX記錄下來它就是描述文件名,使用時不要帶.mobileprovision
如何使用Xcode + personal certificates真機調試
如果需要真機調試,但是又無法獲取蘋果開發者中心頒發的證書,那么可以使用xcode + 免費的開發者賬號進行personal的證書申請。具體操作如下:
打開xcode
,點擊Preferences
選擇Accounts
點擊左下角+
號,使用Apple Id
創建一個新的賬戶。
Apple ID中填寫自己在蘋果這開發中心申請的賬號,完成后點擊Manage Certificates
點擊坐下角+
號,創建一個證書即可,完成之后點擊Done
回到xcode
的工程目錄下,在Signing & Capabilities
面板的Team
下,選擇剛剛創建的Team
然后數據線連上真機,點擊Run
即可。
最后一步,則是在手機設置 -> 通用 -> 設備管理
中,將未受信任的App置為信任即可。
fastlane自動化打包上傳
上面講解了怎么生成certificates、p12以及provisioning profiles,有了這三個文件,現在就可以來打包發布了。這里采用的是fastlane。
網上關於fastlane上的教程很多,這里只是簡單介紹。
fastlane是一個針對iOS和Android應用的Continuous Delivery工具集。能夠自動化測試、截圖以及管理你的provisioning profiles,為你打包上傳應用節省了很多時間。
fastlane is a tool for iOS and Android developers to automate tedious tasks like generating screenshots, dealing with provisioning profiles, and releasing your application.
注:圖上的相關stage在最新的fastlane版本中可能有變化,以官網為准。
基本安裝
安裝最新的xcode
命令行工具
xcode-select --install
安裝fastlane
# Using RubyGems
sudo gem install fastlane -NV
# Alternatively using Homebrew
brew install fastlane
初始化項目
fastlane init
如果你選擇了下載已經存在app的元數據,下面是生成的structure
工具集
到目前為止,Fastlane的工具集大約包含180多個小工具,基本上涵蓋了打包、簽名、測試、部署、發布、庫管理等等移動開發中涉及到的內容。另外Fastlane本身強大的Action和Plugin機制,能夠使你輕松地寫出你自己想要的工具。
代碼簽名(Codesigning)
打包ios之前,最主要的就是要進行代碼簽名,這也是這篇文章上面講解的內容。這里主要有幾種方式:
-
-
A new approach to iOS code signing: Share one code signing identity across your development team to simplify your codesigning setup and prevent code signing issues.
match is the implementation of the codesigning.guide concept. match creates all required certificates & provisioning profiles and stores them in a separate git repository, Google Cloud, or Amazon S3. Every team member with access to the selected storage can use those credentials for code signing. match also automatically repairs broken and expired credentials. It's the easiest way to share signing credentials across teams
-
官方推薦的形式
-
使用git/cloud的形式管理證書
-
能夠自動修復和過期的證書
-
方便在組內分享、管理
-
match是
sync_code_signing
actoin的別名 -
lane :grant do |options| register_devices(devices_file: "./devices.txt") match( git_url: "git@xxx/certificates.git", type: "development", force_for_new_devices: true, app_identifier: ["org.reactjs.native.example.TryWithReactNative"] ) end
-
開發打包(Beta Deployment)
如果證書已經搞定,下面就要使用build_app(gym)
打開發包進行測試了
lane :beta do
sync_code_signing(type: "development") # see code signing guide for more information
build_app(scheme: "TryWithReactNative")
upload_to_testflight
slack(message: "Successfully distributed a new beta build")
end
打包完成之后,可以上傳到預發布平台進行測試。這里有幾個推薦:
-
-
fastlane插件
-
# install fastlane add_plugin appcenter # basic usage appcenter_upload( api_token: "<appcenter token>", owner_name: "<appcenter account name of the owner of the app (username or organization URL name)>", owner_type: "user", # Default is user - set to organization for appcenter organizations app_name: "<appcenter app name (as seen in app URL)>", file: "<path to android build binary>", notify_testers: true # Set to false if you don't want to notify testers of your new release (default: `false`) )
-
-
-
fastlane插件
-
# install fastlane add_plugin pgyer # basic usage lane :beta do gym pgyer( api_key: "7f15xxxxxxxxxxxxxxxxxx141", user_key: "4a5bcxxxxxxxxxxxxxxx3a9e", ) end
-
生產打包(App Store Deployment)
類似於開發打包過程,不過這里是要上傳到蘋果app store中,在此之前記得切換生產發布包的provisioning profiles
lane :release do
capture_screenshots # generate new screenshots for the App Store
sync_code_signing(type: "appstore") # see code signing guide for more information
build_app(scheme: "TryWithReactNative")
upload_to_app_store # upload your app to App Store Connect
slack(message: "Successfully uploaded a new App Store build")
end
結束語
至此,整個App從注冊、打包到發布就已經完全連成一條線了。對於新手小白來說確時是不太容易,至於最后關於fastlane
講解的相關部分,因為自己並沒有個人賬號,采用的是公司生成的證書,所以也沒辦法親自操作截圖,如果有紕漏,敬請諒解。
參考資料
- Understanding iOS Certificates
- A Complete Guide to the Hellish World of iOS app Certificates and Profiles
- What is a provisioning profile & code signing in iOS?
- how to use Apple Developer
- Provisioning profile
- [學習筆記] 非對稱加密和簽名認證
- 如何注冊AppStore開發者賬號?(2019最新版)
- iOS 開發者中的公司賬號與個人賬號之間有什么區別?
- xcode7+iphone免費帳號打包詳解
- 手把手教你搞定ios的證書申請
- iOS開發證書相關知識
- 證書(Certificate)與描述文件(Provisioning Profiles)
- Fastlane使用總結(一)