最近使用fastlane,每當(dāng)新建一個(gè)project/target的時(shí)候,當(dāng)執(zhí)行 match development/adhoc/appstore
時(shí)候糟秘,不同的bundle id對(duì)應(yīng)的target,每次都會(huì)去重新生成certificate,注意不是Provision Profile北戏,這就很麻煩了,因?yàn)樘O(píng)果的個(gè)人開(kāi)發(fā)者賬號(hào)漫蛔,certificate生成是有數(shù)量限制的嗜愈。 development
和 distribution
證書(shū)類型貌似都是只能生成2個(gè)。所以如果按照f(shuō)astlane那種做法的話莽龟,我們只能給兩個(gè)app裝到真機(jī)里面玩玩蠕嫁。這就怕不能愉快的玩下去了,所以我們就得考慮如何復(fù)用已存在certificate毯盈,下面就是介紹如何復(fù)用剃毒。
合并已有證書(shū)到fastlane match
首先一個(gè)很重要的概念就是cert id, 拿到已有證書(shū)的cert id并告訴fastlane, fastlane知道了就不會(huì)去重新生成certificate,只會(huì)去生成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
執(zhí)行上述代碼益缠,會(huì)輸出相應(yīng)的證書(shū)信息,如果該賬號(hào)下有多個(gè)certificat基公,會(huì)全部輸出幅慌,包括development
和distribution
保持好你需要的復(fù)用的證書(shū)cert id。
創(chuàng)建一個(gè)遠(yuǎn)程git倉(cāng)庫(kù)酌媒,保存你的certificates和provisioning profiles
- iOS/macOS證書(shū)的工作主要就是圍繞certificates和provisioning profiles這兩個(gè)文件進(jìn)行的欠痴。
- 倉(cāng)庫(kù)目錄下創(chuàng)建
certs/distribution
和certs/development
目錄,分別存放生成和開(kāi)發(fā)環(huán)境下的相關(guān)證書(shū)文件
生成符合fastlane match的證書(shū)
鑰匙串中導(dǎo)出已有證書(shū)的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
執(zhí)行完上述步驟后秒咨,就生成了fastlane match
想要的certificate喇辽,當(dāng)執(zhí)行match development/adhoc/appstore
命令后,match
就不會(huì)去Apple Development Center重新生成certificate了雨席,而是拿現(xiàn)有的了菩咨,然后分別丟進(jìn)對(duì)應(yīng)git倉(cāng)庫(kù)目錄中,提交陡厘、推送到遠(yuǎn)程抽米。