Use different GoogleService-Info.plist for different build schemes

后端 未结 17 690
梦毁少年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:36

    I noticed that google expects the filename to be GoogleServiceInfo.plist in the code:

     * The method |configureWithError:| will read from the file GoogleServices-Info.plist bundled with
     * your app target for the keys to configure each individual API. To generate your
     * GoogleServices-Info.plist, please go to https://developers.google.com/mobile/add
     *
     * @see GGLContext (Analytics)
     * @see GGLContext (SignIn)
     */
    @interface GGLContext : NSObject
    

    the key phrase is this one

    read from the file GoogleServices-Info.plist bundled with your app target

    So I simply copied the same file and put it into different directories, and bounded it to different targets:

    0 讨论(0)
  • 2020-12-07 08:37

    Here's how to do it in Xamarin C#:

    string plistPath = NSBundle.MainBundle.PathForResource ("GoogleService-Info", "plist");
    Options options = new Options (plistPath);
    App.Configure (options);
    

    Remember to include the Firebase namespace:

    using Firebase.Analytics;
    
    0 讨论(0)
  • 2020-12-07 08:42

    I think you can use this way to configure your GoogleService-Info.plist dynamicly and use different names for different bundle identifiers.

    ciao Andreas

    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info" ofType:@"plist"];
    FIROptions *options = [[FIROptions alloc] initWithContentsOfFile:filePath];
    [FIRApp configureWithOptions:options];
    
    0 讨论(0)
  • 2020-12-07 08:43

    I solved this by this:

        #if STAGING
            if let filePath = Bundle.main.path(forResource: "GoogleService-Info-Dev", ofType: "plist"),
                let options = FirebaseOptions(contentsOfFile: filePath) {
                    FirebaseApp.configure(options: options)
            } else {
                fatalError("GoogleService-Info-Dev.plist is missing!")
            }
        #else
            if let filePath = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist"),
                let options = FirebaseOptions(contentsOfFile: filePath) {
                    FirebaseApp.configure(options: options)
            } else {
                fatalError("GoogleService-Info.plist is missing!")
            }
        #endif
    
    0 讨论(0)
  • 2020-12-07 08:44

    This answer is very much inspired by @abbood's answer, but a bit more specific on how to do it.

    For each of your targets, e.g. dev, stg, prod:

    • Download the corresponding GoogleService-Info.plist to a separate folder named after your target
    • In Xcode, right-click your app folder and choose Add files to "your app"
    • Select the folder containing the target's GoogleService-Info.plist, make sure Copy items if needed and Create groups are selected, check only the corresponding target in the list of targets, and press Add

    That's it. Now you should have something similar to this structure

    When you build a target, the correct GoogleService-Info.plist will be used.

    0 讨论(0)
提交回复
热议问题