[简译] fastlane Tutorial: Getting Started

fastlane
作者:Felix Krause
开源:fastlane
准备知识:command line, code signing and iTunes Connect
ps: 如果这些不会,可以阅读教程

Getting Started

  1. 下载开始项目
  2. 修改Bundle Identifier
  3. 环境要求:
  • 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.如果没有安装,则提示安装。

  1. 安装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

命令行依次输入:

  1. 进入mZone 项目:cd 项目位置
  2. 创建fastlane:fastlane init

如果得到permission denied错误,请在命令前加入sudo

  1. 输入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 输入一个名字
  1. 相关文件
  • Appfile 储存app identifier 和 your Apple ID
  • Fastfile 管理lanes包含的actions
  • Deliverfile 添加提交到App Store 的metadata

1.在metadata文件夹只有en-US,如需配置另一种语言,需要复制一份并重新命名,比如fr-FR
2.其他文件根据项目填写
3.创建名为itunes_rating_config.jsonjson文件,让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

  1. 修改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
  1. 保存文件,命令行输入:
    fastlane provision
  2. 登录 iTunes Connect,可以看到刚才创建的app
  3. 在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

  1. 命令行输入:
    fastlane snapshot init
  2. 生成名为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 相同

  1. 保存并关闭文件,回到终端,按照提示依次:
  2. 添加一个新的 UI Test target
  3. 将 SnapshotHelper.swift 文件拖入 UI Test target
  4. 打开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")
  1. 在Fastfile添加:
  desc "Take screenshots"
  lane :screenshot do
    snapshot
  end
  1. 保存并退出,打开终端输入:
    fastlane screenshot
  2. 完成后,自动打开screenshots.html文件查看

Creating the IPA file

  1. 在Fastfile文件添加:
  desc "Create ipa"
  lane :build do
    increment_build_number
    gym
  end
  1. 保存并退出,打开终端输入:
    fastlane build

Seamless Delivery

  1. 在Fastfile文件添加:
  desc "Upload to App Store"
  lane :upload do
    deliver
  end
  1. 保存并退出,打开终端输入:
    fastlane upload
  2. 预览 HTML,“Does the Preview on path ‘./Preview.html’ look okay for you? (y/n)”,没问题了就选y
  3. 登录iTunes Connect查看,点击Submit for Review

直接上传:

  1. 修改lane
  desc "Upload to App Store and submit for review"
  lane :upload do
    deliver(
      submit_for_review: true
    )
  end
  1. 修改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"
  1. 命令行输入:
    fastlane upload

Putting it All Together

  1. Fastfile文件添加内容:
 desc "Provision, take screenshots, build and upload to App Store"
  lane :do_everything do
    provision
    screenshot
    build
    upload
  end
  1. 命令行输入:
    fastlane do_everything
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,015评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,262评论 1 292
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,727评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,986评论 0 205
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,363评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,610评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,871评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,582评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,297评论 1 242
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,551评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,053评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,385评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,035评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,079评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,841评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,648评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,550评论 2 270

推荐阅读更多精彩内容