安裝
1、安裝xcode命令行工具
xcode-select --install

出現(xiàn)上圖說(shuō)明已經(jīng)安裝,否則會(huì)安裝
2、安裝Fastlane
# Using RubyGems
sudo gem install fastlane -NV
或者
# Alternatively using Homebrew
brew cask install fastlane
· 我是通過(guò):sudo gem install fastlane -NV
可能會(huì)報(bào)如下錯(cuò)誤:
Could not find a valid gem 'fastlane' (>= 0), here is why:
Unable to download data from https://gems.ruby-china.org/ - bad response Not Found 404 (https://gems.ruby-china.org/specs.4.8.gz)

錯(cuò)誤原因:
查看gem源
gem sources

PS:好像是對(duì)的,但是點(diǎn)擊去這個(gè)地址:https://gems.ruby-china.org/發(fā)現(xiàn)

所以需要跟換源
刪除之前的源
gem sources --remove https://gems.ruby-china.org/
增加新的源
gem sources -a https://gems.ruby-china.com
查看源:

然后再執(zhí)行:
sudo gem install fastlane -NV
安裝成功

如果報(bào)錯(cuò):ERROR: While executing gem ... (Errno::EPERM) Operation not permitted - /usr/bin/commander
解決:
sudo gem install -n /usr/local/bin fastlane
使用
1、fastlane init
cd 到項(xiàng)目根目錄
執(zhí)行fastlane init

2、然后到下圖:這里會(huì)彈出四個(gè)選項(xiàng),問(wèn)你想要用Fastlane做什么? 這里我選的是3;
如果你的工程是用cocoapods的那么可能會(huì)提示讓你勾選工程的Scheme;
步驟就是打開你的xcode,
點(diǎn)擊Manage Schemes,
找到你的項(xiàng)目Scheme,在后面的多選框中進(jìn)行勾選,
然后可以手動(dòng)刪除 fastlane文件夾,重新fastlane init一下。
1. ?? Automate screenshots
2. ????? Automate beta distribution to TestFlight (自動(dòng)testfilght型配置)
3. ?? Automate App Store distribution (自動(dòng)發(fā)布型配置)
4. ?? Manual setup - manually setup your project to automate your (需要手動(dòng)配置內(nèi)容)

3、因?yàn)槭巧暇€,所以選擇1

4、登錄Apple ID Username

PS:這個(gè)時(shí)候可能會(huì)報(bào)錯(cuò):Service key is empty

解決:
1、 訪問(wèn)appleid.apple.com/account/manage
會(huì)讓你登錄,回答密保問(wèn)題
2、添加憑據(jù)
fastlane fastlane-credentials add --username 拼接你的id
輸入密碼

3、更新gem源,按照我上面的做法,你已經(jīng)替換了最新的gem源了哦,所以執(zhí)行下面代碼即可解決
sudo gem install fastlane
5、Manage app metadata

成功后生成系列文件

6、配置文件(主要是Fastflie 和 Deiverfile)
Fastflie
剛創(chuàng)建好的如下圖:

改寫為
efault_platform(:ios)
platform :ios do
desc "自定義lane"
lane :qqhl_release do
#increment_build_number
#2.1編譯 選擇scheme和功能
gym(
scheme: "317hu",
workspace: "317hu.xcworkspace",
include_bitcode: false
)
deliver(
#2.2上傳appstore
force: true,
# skip_metadata: true,
skip_screenshots: true,
skip_binary_upload: false,
submit_for_review: true,
automatic_release: true,
price_tier: 0
)
end
end

如果想實(shí)現(xiàn)“一鍵審核”可以給deliver帶上參數(shù)submit_for_review。這樣就真正實(shí)現(xiàn)了一鍵提交App Store審核。如上圖
如果設(shè)置了自動(dòng)升級(jí)bulid版本號(hào)increment_build_number,increment_build_number的作用是防止本地版本的build號(hào)比App Store(或上次)低而做的自動(dòng)增長(zhǎng)版本號(hào)的處理,工程屬性需要如下設(shè)置

Deiverfile:這個(gè)主要寫下更新說(shuō)明,以及是否有廣告標(biāo)識(shí)之類設(shè)置
app_identifier "com.bozhong.jsrmyy" # The bundle identifier of your app
# 2 用戶名,Apple ID電子郵件地址
username "hyc@qqhl.me" # your Apple ID user
# 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: true,
add_id_info_serves_ads: true,
add_id_info_limits_tracking: true
})
#4 更新說(shuō)明
release_notes({
'zh-Hans' => "1.部分頁(yè)面優(yōu)化;
2.修復(fù)已知bug;"
})

7、打包上傳
cd到項(xiàng)目根目錄,執(zhí)行
fastlane 函數(shù)名(在Fastflie中)
#######例如我的
fastlane qqhl_release
成功


參考:
https://github.com/fastlane/fastlane/tree/master/credentials_manager
https://docs.fastlane.tools/best-practices/continuous-integration/#use-of-application-specific-passwords-and-spaceauth
http://www.itdecent.cn/p/19ae8cc865b0
http://www.itdecent.cn/p/baa8ef99795d
http://www.itdecent.cn/p/5d836e89d9d1
fastlane: 解決使用了submit_for_review無(wú)法成功提交審核
https://docs.fastlane.tools/