fastlane
作者:Felix Krause
開源:fastlane
準備知識:command line, code signing and iTunes Connect
ps: 如果這些不會,可以閱讀教程
Getting Started
- 下載開始項目
- 修改Bundle Identifier
- 環境要求:
- OS X 10.9 (Mavericks) or newer
- Ruby 2.0 or newer
- Xcode Command Line Tools (CLT)
- Paid Apple Developer Account
OS X 10.9 (Mavericks) or newer 自帶Ruby 2.0
命令行輸入查看:
ruby -v
驗證Xcode CLT是否安裝:
xcode-select --install
如果已經安裝,出現command line tools are already installed, use "Software Update" to install updates.
如果沒有安裝,則提示安裝。
- 安裝fastlane
命令行輸入:sudo gem install -n /usr/local/bin fastlane --verbose
fastlane 安裝位置為什么是
/usr/local/bin
,請閱讀About System Integrity Protection on your Mac
The fastlane Toolchain
fastlane包含了下列工具集:
-
produce
在iTunes Connect 和 Apple Developer Portal創建新的iOS apps -
cert
自動創建和維護 iOS code signing certificates -
sigh
創建,更新,下載和修復provisioning profiles -
snapshot
自動拍攝iOS app 在每一個設備的 localized screenshots -
frameit
將screenshots放入正確的設備窗口中 -
gym
編譯和打包iOS app -
deliver
上傳screenshots, metadata 和 apps 到 App Store -
pem
自動生成和更新push notification profiles -
spaceship
是一個Ruby 庫,能夠使用 Apple Developer Center 和 iTunes Connect 的APIs -
pilot
自動部署TestFlight并管理 beta testers -
boarding
邀請 beta testers -
match
使用Git同步certificates 和 provisioning profiles -
scan
運行tests
Setting up fastlane
命令行依次輸入:
- 進入mZone 項目:
cd 項目位置
- 創建fastlane:
fastlane init
如果得到
permission denied
錯誤,請在命令前加入sudo
- 輸入Apple ID 和 密碼
如果出現
Connection reset by peer - SSL_Connect
錯誤
按照提示更新ruby版本,命令行依次輸入:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update && brew install ruby
-
sudo gem install fastlane --verbose
如果出現
This app identifier doesn't exist on iTunes Connect yet, it will be created for you This app identifier doesn't exist on the Apple Developer Portal yet, it will be created for you Please confirm the above values (y/n)
則輸入y
確認
如果出現
It looks like that mZone Poker has already been taken by someone else, please enter an alternative App Name:
則為app 輸入一個名字
- 相關文件
- Appfile 儲存app identifier 和 your Apple ID
- Fastfile 管理lanes包含的actions
- Deliverfile 添加提交到App Store 的metadata
1.在metadata文件夾只有en-US
,如需配置另一種語言,需要復制一份并重新命名,比如fr-FR
2.其他文件根據項目填寫
3.創建名為itunes_rating_config.json
的json
文件,讓iTunes Connect 知道rating criteria,內容為:
{
"CARTOON_FANTASY_VIOLENCE": 0,
"REALISTIC_VIOLENCE": 0,
"PROLONGED_GRAPHIC_SADISTIC_REALISTIC_VIOLENCE": 0,
"PROFANITY_CRUDE_HUMOR": 0,
"MATURE_SUGGESTIVE": 0,
"HORROR": 0,
"MEDICAL_TREATMENT_INFO": 0,
"ALCOHOL_TOBACCO_DRUGS": 0,
"GAMBLING": 2,
"SEXUAL_CONTENT_NUDITY": 0,
"GRAPHIC_SEXUAL_CONTENT_NUDITY": 0,
"UNRESTRICTED_WEB_ACCESS": 0,
"GAMBLING_CONTESTS": 0
}
4.向metadata目錄添加AppIcon
的圖片
5.其他fastlane設置 鍵列表
Creating Certificates and Provisioning Profiles
- 修改Fastfile,內容為:
# This is the minimum version number required.
# Update this, if you use features of a newer version
fastlane_version "2.6.0"
default_platform :ios
platform :ios do
# 1 lane 的描述
desc "Creating a code signing certificate and provisioning profile"
# 2 命名這個lane為provision
lane :provision do
# 3 在iTunes Connect 和 the Developer Portal 創建app
produce(
app_name: 'YOUR_UNIQUE_APP_NAME',
language: 'English',
app_version: '1.0',
sku: '123abc'
)
# 4 創建私有密鑰和簽名請求,下載并安裝產生的證書,導入在keychain生成的文件
cert
# 5 生成 provisioning profile,force: true表示每次運行都創建provisioning profile,默認為distribution profile。使用sigh(adhoc: true) 創建ad hoc profile, 使用sigh(development: true) 創建 development profile
sigh(force: true)
end
error do |lane, exception|
# This block is called if there was an error running a lane.
end
end
- 保存文件,命令行輸入:
fastlane provision
- 登錄 iTunes Connect,可以看到剛才創建的app
- 在Xcode 中使用創建的 provisioning profile
1.在Target\Build Settings\Code Signing
設置provisioning profile為新創建的 <app ID> AppStore,選擇對應的Code Signing Identity
2.在Target\General
關閉Automatically manage signing,在Signing (Debug) 和 Signing (Release) 選擇與剛才相同的 provisioning profile
Screenshots Made Easy
- 命令行輸入:
fastlane snapshot init
- 生成名為Snapfile的文件,修改內容為:
# A list of devices you want to take the screenshots from
devices([
"iPhone 5",
"iPhone 6",
"iPhone 6 Plus"
])
# A list of supported languages
languages([
'en-US',
'fr-FR'
])
# Where should the resulting screenshots be stored?
output_directory "./fastlane/screenshots"
# Clears previous screenshots
clear_previous_screenshots true
# Latest version of iOS
ios_version '10.1'
為什么沒有 iPhone 7 和 iPhone 7 Plus 呢?
因為與 iPhone 6 and iPhone 6 Plus 相同
- 保存并關閉文件,回到終端,按照提示依次:
- 添加一個新的 UI Test target
- 將 SnapshotHelper.swift 文件拖入 UI Test target
- 打開mZone_PokerUITests.swift文件,刪除 setUp 和 tearDown 方法,在
testExample
方法添加以下代碼:
// 1
let app = XCUIApplication()
setupSnapshot(app)
app.launch()
// 2
let chipCountTextField = app.textFields["chip count"]
chipCountTextField.tap()
chipCountTextField.typeText("10")
// 3
let bigBlindTextField = app.textFields["big blind"]
bigBlindTextField.tap()
bigBlindTextField.typeText("100")
// 4
snapshot("01UserEntries")
// 5
app.buttons["what should i do"].tap()
snapshot("02Suggestion")
- 在Fastfile添加:
desc "Take screenshots"
lane :screenshot do
snapshot
end
- 保存并退出,打開終端輸入:
fastlane screenshot
- 完成后,自動打開screenshots.html文件查看
Creating the IPA file
- 在Fastfile文件添加:
desc "Create ipa"
lane :build do
increment_build_number
gym
end
- 保存并退出,打開終端輸入:
fastlane build
Seamless Delivery
- 在Fastfile文件添加:
desc "Upload to App Store"
lane :upload do
deliver
end
- 保存并退出,打開終端輸入:
fastlane upload
- 預覽 HTML,“Does the Preview on path ‘./Preview.html’ look okay for you? (y/n)”,沒問題了就選y
- 登錄iTunes Connect查看,點擊Submit for Review
直接上傳:
- 修改lane
desc "Upload to App Store and submit for review"
lane :upload do
deliver(
submit_for_review: true
)
end
- 修改Deliverfile文件內容為:
# 1 免費app
price_tier 0
# 2 review 信息
app_review_information(
first_name: "YOUR_FIRST_NAME",
last_name: "YOUR_LAST_NAME",
phone_number: "YOUR_PHONE_NUMBER",
email_address: "YOUR_EMAIL_ADDRESS",
demo_user: "N/A",
demo_password: "N/A",
notes: "No demo account needed"
)
# 3 提交信息
submission_information({
export_compliance_encryption_updated: false,
export_compliance_uses_encryption: false,
content_rights_contains_third_party_content: false,
add_id_info_uses_idfa: false
})
# 4 審核通過后手動release
automatic_release false
# 5 提供app icon 文件
app_icon './fastlane/metadata/AppIcon.png'
# 6 提供 iTunes Rating Configuration 文件
app_rating_config_path "./fastlane/metadata/itunes_rating_config.json"
- 命令行輸入:
fastlane upload
Putting it All Together
- Fastfile文件添加內容:
desc "Provision, take screenshots, build and upload to App Store"
lane :do_everything do
provision
screenshot
build
upload
end
- 命令行輸入:
fastlane do_everything