Firebase migration

Firebase 導入

  • 在 Cartfile 加入

      binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseAnalyticsBinary.json"
  • 打開 terminal,在專案下執行

      Carthage update --platform iOS
  • 打開 Xcode 專案,依下列步驟設定

    • Build Phases

    • Link Binary With Libraries

    • 左下角 +

    • Add Other -> Add Files

    • 至 Carthage/Build/iOS,選取 Firebase 相關 Framework,點右下角 Open 加入

      PS:不要加進 Embed Frameworks,因為 Firebase 的 Framework 都是 Static Library
  • 至 Build Settings->Other Linker Flags 新增 -ObjC

    • 若遇到 Duplicate Symbole 問題(如難字 Library),則改用 -force_load 來新增,如下

      -force_load Carthage/Build/iOS/FIRAnalyticsConnector.framework/FIRAnalyticsConnector 
      -force_load Carthage/Build/iOS/FirebaseAnalytics.framework/FirebaseAnalytics 
      -force_load Carthage/Build/iOS/FirebaseCore.framework/FirebaseCore 
      -force_load Carthage/Build/iOS/FirebaseCoreDiagnostics.framework/FirebaseCoreDiagnostics 
      -force_load Carthage/Build/iOS/FirebaseInstanceID.framework/FirebaseInstanceID 
      -force_load Carthage/Build/iOS/GoogleAppMeasurement.framework/GoogleAppMeasurement 
      -force_load Carthage/Build/iOS/GoogleUtilities.framework/GoogleUtilities 
      -force_load Carthage/Build/iOS/GoogleDataTransport.framework/GoogleDataTransport 
      -force_load Carthage/Build/iOS/GoogleDataTransportCCTSupport.framework/GoogleDataTransportCCTSupport 
      -force_load Carthage/Build/iOS/nanopb.framework/nanopb
  • 至 Firebase 官網,下載 GoogleService-Info.plist,並將該檔案加入專案

    PS:Firebase 相關存取權限,請洽資規科
  • 打開 AppDelegate,加入以下程式碼

    • objective-c

        @import UIKit;
        @import Firebase;    // 加入此行
      
        @implementation AppDelegate
      
        - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
        {
          [FIRApp configure];    // 加入此行
          return YES;
        }
    • swift

        import UIKit
        import Firebase    // 加入此行
      
        @UIApplicationMain
        class AppDelegate: UIResponder, UIApplicationDelegate 
        {
          var window: UIWindow?
      
          func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool 
          {
            FirebaseApp.configure()    // 加入此行
            return true
          }
        }

Fastlane 設定 - Firebase App Distribution

  • 點我下載,解壓縮後取得三個檔案

    • Gemfile(放在專案下)

    • Gemfile.lock(放在專案下)

    • Pluginfile(放在專案 fastlane 資料夾下)

  • 參考下列代碼,在註解的地方進行修改 Fastfile

desc "Firebase App_distribution"
lane :beta do |values|

  env=values[:env]
  notes = values[:notes] ? values[:notes] : 'It is '+env+' environment'

  build_ios_app(scheme: 'CathayLifeAppStore.'+env,    // 請改成各自專案的 scheme 名稱
                export_options: {
                  method: "enterprise",
                  provisioningProfiles: provisioningProfiles
                }
  )

  firebase_app_distribution(
      app: "1:8156708xxxxx:ios:9ef3c94020c178627xxxxx",  // 請參照 GoogleService-Info.plist 的 GOOGLE_APP_ID
      groups: "cathayappstore-ios",        // 請在 Firebase 自訂測試群組名稱
      release_notes: notes,
      firebase_cli_path: "/usr/local/bin/firebase",
      firebase_cli_token: ENV["FIREBASE_TOKEN"]
  )

  upload_symbols_to_crashlytics(api_token: '210cae29d9313bf20a7895e227a817eb0d9bac8d')

end
  • 將以上修改 push 上 Git,並進行發布以測試是否正常運作

  • 收到邀請信後,會打開一個下載測試版的連結,可參考以下步驟在桌面建立捷徑,方便下次使用

Last updated