LoginSignup
44
40

More than 5 years have passed since last update.

FirebaseをStaging環境とかDebug環境とかRelease環境で切り替えをする

Posted at

はじめに

Firebaseをアプリに実装していてDeployGateなどでテストをしているとRelease環境のAnalyticsが反応してしまって実際の生の完全なデータが取得できないので GoogleService-Info.plist を2つ取得してそれぞれの環境にわけてあげようという話です。

プロジェクト準備

  1. Xcodeでプロジェクトを新しく作る
  2. Firebaseでプロジェクトを作る
  3. 普通にFirebaseとiOSアプリの設定をする
  4. スキームの設定 Xcode7 でスキームの設定をするこの記事を見るとわかります!

上記のところまでは省略します。

スクリーンショット 2016-09-12 午後1.28.33.png

こんな状態まではセットアップしておく

FirebaseにStaging用のプロジェクトを作る(必要ならDebug用も)

Release環境と同じようにプロジェクトを作成し、 GoogleService-Info.plist をダウンロードする。

ダウンロードした GoogleService-Info.plistGoogleService-Info-Staging.plist とリネームして、プロジェクトに追加する。

スクリーンショット 2016-09-12 午後1.43.44.png

追加する際にStaging環境にtargetが選択されていることを確認する。

AppDelegate.swift
import UIKit
import Firebase

#if STAGING
    let firebasePlistName = "GoogleService-Info-Staging"
#else
    let firebasePlistName = "GoogleService-Info"
#endif

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        let firbaseOptions = FIROptions(contentsOfFile: NSBundle.mainBundle().pathForResource(firebasePlistName, ofType: "plist"))
        FIRApp.configureWithOptions(firbaseOptions)
        return true
    }
    ・・・
}

これでRelease環境とDebug環境のFirebaseを切り替えることができました!

44
40
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
44
40