說明
具體的Fastlane安裝使用我這里就不多說了 網(wǎng)上一大片文檔 只記錄一下使用時候遇到場景的想法和解決方式
官方文檔:Fastlane Docs
場景
我們項目一般是分企業(yè)包和非企業(yè)包 一個(企業(yè)證書)負(fù)責(zé)分發(fā) 一個是供指定設(shè)備安裝測試
一般常見有兩種處理方式:
A、添加不同多targets 區(qū)分企業(yè)包和開發(fā)包identifier 和證書或一些配置項 在打包時選擇一個target去打包就可以 如圖:多個target
這種方式使用fastlane打包可以參考Fastlane 實現(xiàn)多 Target 自動化打包發(fā)布這篇文章
B、項目中只維護(hù)一個主target 同時添加了一些Service Extension(如上圖 添加了widget、watch、notification 等extension)
在使用fastlane打包時 我們考慮到企業(yè)包和非企業(yè)包的bundle identifier 和 sign certificate 不一樣 我們暫時又不打算以分倉庫或再在項目中加一次targets來區(qū)分企業(yè)包(如A)
所以想到腳本的方式去改變bundle id 和sign cer 替換為企業(yè)包的一些配置包括改target extension 的配置 這樣可以達(dá)到一個項目可以一鍵分別打企業(yè)包和非企業(yè)包測試 抱著這個想法查了一遍官方文檔 發(fā)現(xiàn)是有這個指令automatic_code_signing
| Key | Description | Default |
|---|---|---|
path |
Path to your Xcode project | * |
use_automatic_signing |
Defines if project should use automatic signing | false |
team_id |
Team ID, is used when upgrading project | |
targets |
Specify targets you want to toggle the signing mech. (default to all targets) | |
code_sign_identity |
Code signing identity type (iPhone Developer, iPhone Distribution) | |
profile_name |
Provisioning profile name to use for code signing | |
profile_uuid |
Provisioning profile UUID to use for code signing | |
bundle_identifier |
Application Product Bundle Identifier |
但發(fā)現(xiàn)好像并不能滿足我們的需求 每個targets extension的bundle identifier是獨立的
所以經(jīng)過我們測試找到了這個方法update_app_identifier
Code Example
Update an app identifier by either setting CFBundleIdentifier or PRODUCT_BUNDLE_IDENTIFIER, depending on which is already in use.
update_app_identifier(
xcodeproj: "Example.xcodeproj", # Optional path to xcodeproj, will use the first .xcodeproj if not set
plist_path: "Example/Info.plist", # Path to info plist file, relative to xcodeproj
app_identifier: "com.test.example" # The App Identifier
)
處理多個target extension
platform :ios do
desc "打包企業(yè)版 更改項目和擴展bundle id"
lane :test do
update_app_identifier(
xcodeproj: "testApp.xcodeproj",
app_identifier: "com.testApp.testAppPublic",
plist_path: "testApp/Supporting\ Files/Info.plist",
)
update_app_identifier(
app_identifier: "com.testApp.testAppPublic.Extension",
plist_path: "testAppExtension/Supporting\ Files/Info.plist",
)
.........
automatic_code_signing(
use_automatic_signing: true,
team_id: "xxxxxxx",
)
其實也是實現(xiàn)了一個lane的腳本函數(shù) 每個Extension都配置執(zhí)行一次update_app_identifier 來更新bundle identifier 和 plist_path
當(dāng)然你也可以自己寫腳本去改.xcodeproj的配置項來做更多的更改
