Use different GoogleService-Info.plist for different build schemes

后端 未结 17 765
梦毁少年i
梦毁少年i 2020-12-07 07:49

I am using a build scheme for prod and one for staging (with 2 different bundle identifiers) and I am trying to use a separate GoogleService-Info.plist for each scheme. Is t

17条回答
  •  没有蜡笔的小新
    2020-12-07 08:34

    Check this article: https://medium.com/@brunolemos/how-to-setup-a-different-firebase-project-for-debug-and-release-environments-157b40512164

    On Xcode, create two directories inside your project: Debug and Release. Put each GoogleService-Info.plist file there.

    On AppDelegate.m, inside the didFinishLaunchingWithOptions method, put the code:

    Objective-C

      NSString *filePath;
    #ifdef DEBUG
      NSLog(@"[FIREBASE] Development mode.");
      filePath = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info" ofType:@"plist" inDirectory:@"Debug"];
    #else
      NSLog(@"[FIREBASE] Production mode.");
      filePath = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info" ofType:@"plist" inDirectory:@"Release"];
    #endif
    
      FIROptions *options = [[FIROptions alloc] initWithContentsOfFile:filePath];
      [FIRApp configureWithOptions:options];
    

    Swift 4

    var filePath:String!
    #if DEBUG
        print("[FIREBASE] Development mode.")
        filePath = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist", inDirectory: "Debug")
    #else
        print("[FIREBASE] Production mode.")
        filePath = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist", inDirectory: "Release")
    #endif
    
    let options = FirebaseOptions.init(contentsOfFile: filePath)!
    FirebaseApp.configure(options: options)
    

    Drag & drop both Debug and Release folders to the Build Phases > Copy Bundle Resources:

    That's it :)

提交回复
热议问题