segment-integrations / analytics-ios-integration-firebase

Segment's bundled integration for Firebase on iOS
MIT License
13 stars 95 forks source link

Is it possible to read a different GoogleService-Info.plist file #66

Closed paravena closed 2 years ago

paravena commented 3 years ago

I'm not good with Objective-C, but is there a way I can pass a reference to a different plist file, the purpose of this is to support different environments, it looks like this code always goes for the default GoogleService-Info.plist file.

NSString *plistFile = [[NSBundle mainBundle] pathForResource:@"GoogleService-QA-Info" ofType:@"plist"];
  NSDictionary *firebaseConf = [NSDictionary dictionaryWithContentsOfFile:plistFile];

  SEGAnalyticsConfiguration *configuration = [SEGAnalyticsConfiguration configurationWithWriteKey:@"SEGMENT_API_KEY"];
  configuration.trackApplicationLifecycleEvents = YES;          // Enable this to record certain application events automatically!
  configuration.recordScreenViews = YES;                        // Enable this to record screen views automatically!
  configuration.flushAt = 1;                                    // Flush events to Segment every 1 event
  [configuration use:[SEGFirebaseIntegrationFactory instance]]; // Use Firebase
  [SEGAnalytics setupWithConfiguration:configuration];
  [SEGAnalytics debug:YES];

Any ideas are welcome

rico237 commented 3 years ago

@paravena you can use FIRApp & FIROptions for this.

Here is what you can do (tested in my own project with multiple environements):

@import Firebase;

...

FIROptions* firebaseOptions = [[FIROptions alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"GoogleService-QA-Info" ofType:@"plist"]];
if (firebaseOptions != nil) {
    [FIRApp configureWithOptions:firebaseOptions];
    [configuration use:[SEGFirebaseIntegrationFactory instance]];
}
bsneed commented 2 years ago

Seems to be solved, closing.