In new Firebase, how to use multiple config file in xcode?

后端 未结 9 1465
被撕碎了的回忆
被撕碎了的回忆 2021-01-30 09:14

Hey I am playing with the new firebase iOS SDK, in my project, I have only one target, I created two configurations, Debug and Release, with different bundler identifier, but se

9条回答
  •  情歌与酒
    2021-01-30 09:38

    Add both Google Service plists to your project, with different names:

    Then for each Build Scheme, select Edit Scheme and add a unique value for an environment variable like so:

    So the other build scheme's BUILD_FOR environment variable would be set to "DEV", for example.

    Then, you would check for this variable in App Delegate and configure the FIRApp according to which scheme was built:

        let buildFor = ProcessInfo.processInfo.environment["BUILD_FOR"]! as String
        var firebasePlistFileName = "GoogleService-Info"
    
        if buildFor == "PROD" {
            firebasePlistFileName = "GoogleService-Prod-Info"
        }
    
        let firbaseOptions = FIROptions(contentsOfFile: Bundle.main.path(forResource: firebasePlistFileName, ofType: "plist"))
        FIRApp.configure(with: firbaseOptions!)
    

提交回复
热议问题