效率神器Fastlane 之登錄校驗

做爲一位iOS開發者,或者自動化測試工做者,你們都或多或少的接觸或者據說過fastlane,今天主要講一下fastlane的最基本使用和登錄校驗問題!git

什麼是fastlane

fastlane is the easiest way to automate beta deployments and releases for your iOS and Android apps. 🚀 It handles all tedious tasks, like generating screenshots, dealing with code signing, and releasing your application.github

怎麼安裝

// 安裝最新的Xcode command line tools
xcode-select --install
// 安裝 fastlane
sudo gem install fastlane -n /usr/local/bin

複製代碼

基礎使用場景

  1. 上傳testflight
  2. 上傳apple store
  3. fastlane自有action
  4. 自定義 action
    • 自定義上傳私有庫Action
    • 內網分發
    • ...

使用

假設咱們歷來沒有使用過fastlane,咱們來總結一下步驟:json

  1. 進入一個Xcode項目跟目錄xcode

  2. 執行fastlane initruby

    fastlane init
    
    新版本安裝的時候出現了下面的分支選擇,按要求選擇就行
    
    1. 📸  Automate screenshots
    2. 👩‍✈️  Automate beta distribution to TestFlight (自動testfilght型配置)
    3. 🚀  Automate App Store distribution (自動發佈型配置)
    4. 🛠  Manual setup - manually setup your project to automate your (須要手動配置內容)
    
    3
    [10:42:34]: Please enter your Apple ID developer credentials
    [10:42:34]: Apple ID Username:
    xxxxxxx@126.com
    [10:43:17]: Logging in...
    [10:43:22]: ✅  Logging in with your Apple ID was successful
    因爲我以前配置過帳號密碼,因此直接就經過了 ,剩下的步驟隨便選擇
    複製代碼
  3. 執行 fastlane release ,愉快的等待打包上傳的過程bash

  4. 若是帳號沒有開啓兩步驗證的話,到這裏,整個打包過程就結束了.可是做爲開發者的咱們,經歷過去年 apple的一輪協議更新,主帳號通常都開啓了兩步驗證了,所以咱們很是悲催的發現一個場景,在連接apple connect的時候,它報錯了session

    [12:00:06]: Login to App Store Connect (XXXXXXXX@163.com)
    [12:00:13]: Login successful
    [12:00:18]: Ready to upload new build to TestFlight (App: 100000000)...
    [12:00:23]: Fetching password for transporter from environment variable named `FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD`
    [12:00:23]: Going to upload updated app to App Store Connect
    [12:00:23]: This might take a few minutes. Please don't interrupt the script. [12:00:34]: [Transporter Error Output]: Your Apple ID or password was entered incorrectly. (-20101)  ------------------------------------------------------------------------------------- Please provide your Apple Developer Program account credentials The login information you enter will be stored in your macOS Keychain You can also pass the password using the `FASTLANE_PASSWORD` environment variable See more information about it on GitHub: https://github.com/fastlane/fastlane/tree/master/credentials_manager ------------------------------------------------------------------------------------- 複製代碼
  5. 登陸帳號管理獲取app專用密碼 appleid.apple.com/account/man…app

  6. 編輯zshrc文件 open ~/.zshrcdom

    source ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
    
    alias code='/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code'
    # 添加全局變量
    export FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD=App專用密碼
    複製代碼

    執行下 source ~/.zshrcide

  7. 獲取 FASTLANE_SESSION

    fastlane spaceauth -u appleId
    Logging into to App Store Connect (xxxxxxxx@163.com)...
    Available session is not valid any more. Continuing with normal login.
    Successfully logged in to App Store Connect
    
    ---
    
    Pass the following via the FASTLANE_SESSION environment variable:
    ---\n- !ruby/object:HTTP::Cookie\n  name: DES5615ee1ca80587ae9a69d81e576853164\n  value: HSARMTKNSRVXWFlaEvzCiaueSue3lJT7k2RbYnFJWaPCa50RJ4/qZ/Rh+pWnT0xLd+ePTS+i0ax6lBWEDVFs4mkv0YvOz1vJ56g126teanj4GLP+zwxZ5zksmVgxJ9TSb5BsoxuNSRVX\n  domain: idmsa.apple.com\n  for_domain: true\n  path: "/"\n  secure: true\n  httponly: true\n  expires: \n  max_age: 2592000\n  created_at: 2019-11-05 17:27:39.027306000 +08:00\n  accessed_at: 2019-11-06 10:10:33.027385000 +08:00\n- !ruby/object:HTTP::Cookie\n  name: myacinfo\n  value: DAWTKNV284d18c02b8b7e0ca9687a20890887b33ce164be953177dca4d54b1d8a34b306c7cdd46176f09b8c9ad921de647d38cc83c8446ae8937cf86fd205645a8e95d91a29821136c1181fd68b8d39b57dda5f5f84b7159c10ebd1e255b2fe54c07554d48968d98efaed82f3e97fbafad209a7bc8de3f4326a9ea76d919e1951463092e7b300e3edd95514182808a1ea951abd7d548e02da08cd9e5e359586d466c7c3ab32862e7a3c606e9945b9213e882ffa2fd5c8d8864178a0525e9d3f1ab2bdffab62aa3584fe1e1cedb047ee709095216bc432ac19c1c1416aec3edc87cc8de22491094d283fcf41b6f9f737205a8d26c24760ec14de91a14412f4ce751f4fd0e36326661663463336263393834623365356133386331373638303164666633633539353862663766MVRYV2\n  domain: apple.com\n  for_domain: true\n  path: "/"\n  secure: true\n  httponly: true\n  expires: \n  max_age: \n  created_at: 2019-11-06 10:10:35.096023000 +08:00\n  accessed_at: 2019-11-06 10:10:35.097007000 +08:00\n- !ruby/object:HTTP::Cookie\n  name: dqsid\n  value: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1NzMwMDYyMzUsImp0aSI6IjdJTWVKdXJmWjVWNk9fNmh1QWR6RncifQ.LHAoqXse1mFQY5DEr4PcuzFRf0juWFXrFYdur1kDFW8\n  domain: appstoreconnect.apple.com\n  for_domain: false\n  path: "/"\n  secure: true\n  httponly: true\n  expires: \n  max_age: 1799\n  created_at: &1 2019-11-06 10:10:36.292923000 +08:00\n  accessed_at: *1\n
    
    
    Example:
    export FASTLANE_SESSION='XXX'
    複製代碼
  8. 編輯.zshrc文件open ~/.zshrc

    source ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
    
    alias code='/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code'
    # 添加全局變量
    export FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD=App專用密碼
    
    #添加FASTLANE_SESSION
    export FASTLANE_SESSION='XXX'
    複製代碼

    執行下 source ~/.zshrc

  9. Finished!

須要注意的地方:

針對於開啓兩步驗證的問題,須要注意的是 FASTLANE_SESSION是有有效期的, 如今的有效期是一個月,若是發現FASTLANE_SESSION 無效的時候須要從新生成下FASTLANE_SESSION.

一個trick

既然二步驗證後,FASTLANE_SESSION存在過時時間,那麼咱們能夠新建一個子帳號,不開啓兩步驗證便可規避,實際驗證是可行的! 不過有一點須要確認,電腦上安裝的證書包含該帳號!

預告

下一節講一下 fastlane match來管理證書,來規避一些證書管理致使的風險和問題!

A new approach to iOS code signing: Share one code signing identity across your development team to simplify your codesigning setup and prevent code signing issues.

相關文章
相關標籤/搜索