最近使用fastlane,每當新建一個project/target的時候,當執行 match development/adhoc/appstore
時候,不同的bundle id對應的target,每次都會去重新生成certificate,注意不是Provision Profile,這就很麻煩了,因為蘋果的個人開發者賬號,certificate生成是有數量限制的。 development
和 distribution
證書類型貌似都是只能生成2個。所以如果按照fastlane那種做法的話,我們只能給兩個app裝到真機里面玩玩。這就怕不能愉快的玩下去了,所以我們就得考慮如何復用已存在certificate,下面就是介紹如何復用。
合并已有證書到fastlane match
首先一個很重要的概念就是cert id, 拿到已有證書的cert id并告訴fastlane, fastlane知道了就不會去重新生成certificate,只會去生成Progision Porfile
。
下面一段ruby
代碼就是獲取cert id:
require 'spaceship'
Spaceship.login('your@apple.id')
Spaceship.select_team
Spaceship.certificate.all.each do |cert|
cert_type = Spaceship::Portal::Certificate::CERTIFICATE_TYPE_IDS[cert.type_display_id].to_s.split("::")[-1]
puts "Cert id: #{cert.id}, name: #{cert.name}, expires: #{cert.expires.strftime("%Y-%m-%d")}, type: #{cert_type}"
end
執行上述代碼,會輸出相應的證書信息,如果該賬號下有多個certificat,會全部輸出,包括development
和distribution
保持好你需要的復用的證書cert id。
創建一個遠程git倉庫,保存你的certificates和provisioning profiles
- iOS/macOS證書的工作主要就是圍繞certificates和provisioning profiles這兩個文件進行的。
- 倉庫目錄下創建
certs/distribution
和certs/development
目錄,分別存放生成和開發環境下的相關證書文件
生成符合fastlane match的證書
鑰匙串中導出已有證書的certificate.cer和certificate.p12文件
run
openssl pkcs12 -nocerts -nodes -out key.pem -in certificate.p12
.
It will extract the private key to a key.pem file.-
encrypt the files with
openssl aes-256-cbc -k your_password -in key.pem -out cert_id.p12 -a openssl aes-256-cbc -k your_password -in certificate.cer -out cert_id.cer -a
執行完上述步驟后,就生成了fastlane match
想要的certificate,當執行match development/adhoc/appstore
命令后,match
就不會去Apple Development Center重新生成certificate了,而是拿現有的了,然后分別丟進對應git倉庫目錄中,提交、推送到遠程。