IOS 中什么是 Fastlane?如何使用?代码举例讲解

Fastlane 是一款开源的自动化测试和发布工具,它可以帮助我们轻松地进行:
• 测试设备部署(TestFlight、App Store)
• 截屏和将截屏上传到 iTunes Connect
• 编译.ipa 文件并上传到 iTunes Connect和 TestFlight
• 提取并上传 dSYM 文件
• 管理 iTunes Connect 中的测试用户和设备 等等。

使用 Fastlane 的基本步骤:

  1. 安装 Fastlane,通过 Gem 安装:
sudo gem install fastlane
  1. 初始化 Fastlane 项目,会生成 Fastfile:
fastlane init
  1. 打开 Fastfile 配置各个 lane,例如:
ruby
lane :test do
  scan                  # 运行测试
  testfairy              # 上传构建到TestFairy  
end

lane :beta do
  cert                    # 创建证书
  sigh                    # 签名ipa
  testflight              # 将ipa文件上传到iTunes Connect用于测试
end
  1. 执行 lane 进行自动化任务:
fastlane test
fastlane beta
  1. Fastlane 会执行 lane 中的各个 action 来完成测试部署、ipa 包签名和上传等任务。
    下面是一个完整的例子:
ruby
default_platform(:IOS)

platform :IOS do
  desc "Runs all the tests"
  lane :test do
    scan
  end

  desc "Submit a new Beta Build to TestFlight"
  lane :beta do
    cert
    sigh
    upload_to_testflight
  end
end