LoginSignup
8
9

More than 5 years have passed since last update.

Firebaseの設定ファイルをスキーマ毎に切り替える

Posted at

Firebaseの設定を切り替えたかったんですけどちょっと時間がかかったのでメモを残しておきます

スキーマで設定ファイル(GoogleService-Info.plist)を切り分けて読み込みたかったのですが、AndroidのFlavorで切り分けることはできないのでどうしようかとDocumentをあさって解決しました
尚、PreProcessorはスキーマ毎にPRODUCTION、STAGING、DEVELOPMENTといった感じに定義しています

#if PRODUCTION
let filePath = NSBundle.mainBundle().pathForResource("GoogleService-Info-pro", ofType: "plist")
#elseif STAGING
let filePath = NSBundle.mainBundle().pathForResource("GoogleService-Info-stg", ofType: "plist")
#else
let filePath = NSBundle.mainBundle().pathForResource("GoogleService-Info-dev", ofType: "plist")
#endif
let firebaseOption = FIROptions(contentsOfFile: filePath)
FIRApp.configureWithOptions(firebaseOption)

これでいい感じに設定ファイルを切り替えることができます
ただし、FirebaseのVersionが新しくないとダメっぽいです(検証環境version3.5.1)

8
9
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
8
9