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

后端 未结 9 1462
被撕碎了的回忆
被撕碎了的回忆 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:43

    Using Objective-C, in your AppDeletage.m:

    NSString *filePath;
    #ifdef DEBUG
      filePath = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info-Debug" ofType:@"plist"];
    #else
      filePath = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info-Production" ofType:@"plist"];
    #endif
    
      FIROptions *options = [[FIROptions alloc] initWithContentsOfFile:filePath];
      [FIRApp configureWithOptions:options];
    
    0 讨论(0)
  • 2021-01-30 09:43

    I see a lot of responses using Targets, but if you want to differentiate by scheme you can go to:

    Edit Schemes... > Select Scheme > Build > Post-Action

    • Add a Run Script
    • Provide build settings from: (select the target you want to)
    • Add following script
    PATH_TO_GOOGLE_PLISTS="${PROJECT_DIR}/MVCVMRC/Supporting Files/FirebasePlist"
    
    cp -r "$PATH_TO_GOOGLE_PLISTS/Brazil/GoogleService-Info-preprod.plist" "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/GoogleService-Info.plist"
    

    Don't forget to change the PATH_TO_GOOGLE_PLISTS

    Sample:

    0 讨论(0)
  • 2021-01-30 09:44

    Better approach if you have single target is to just name your configs appropriately and load them as below. Seems to work fine for UAT environment example : Swift 3.0

        var fireBaseConfigFile = Bundle.main.path(forResource: "GoogleService-Info-PROD", ofType: "plist")
       #if UAT
           fireBaseConfigFile = Bundle.main.path(forResource: "GoogleService-Info-UAT", ofType: "plist")
       #endif
    
       guard let firOptions = FIROptions(contentsOfFile: fireBaseConfigFile) else {
           assert(false, "Failed to load Firebase config file")
           return
       }
    
       FIRApp.configure(with: firOptions)
    
    0 讨论(0)
提交回复
热议问题