segment-integrations / analytics-ios-integration-firebase

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

Compatibility with react-native-firebase #18

Closed rodrijuarez closed 3 years ago

rodrijuarez commented 6 years ago

Issue

I'm trying to integrate this library with react-native-firebase but I'm finding the problem that both libraries instantiate twice the FIRApp, I've sorted out through the compatibility issues regarding versions, but I can't do much more about this, I've to instantiate the FIRApp in my AppDelegate given that I want to do something like this in my JS code:

  componentDidMount() {
    firebase.app().onReady()
      .then(() => {
        console.log('firebase app ready')
      });
  }

I want to do this to do permissions request or check dynamic links or if the app was opened by FCM. Is there any way for me to solve this or any help by the library so FIRApp isn't instantiated twice if there's an existing FIRApp? In case I wait for the FIRApp initialisation by this library my app crashes with this error message, this is probably because the JS is loaded before the initialisation of Firebase by this library:

The [__FIRAPP_DEFAULT] firebase app has not been initialized!

Code where the application crashes

File: SEGFirebaseIntegration.m

- (id)initWithSettings:(NSDictionary *)settings
{
    if (self = [super init]) {
        self.settings = settings;
        self.firebaseClass = [FIRAnalytics class];
        NSString *deepLinkURLScheme = [self.settings objectForKey:@"deepLinkURLScheme"];
        if (deepLinkURLScheme) {
            [FIROptions defaultOptions].deepLinkURLScheme = deepLinkURLScheme;
            SEGLog(@"[FIROptions defaultOptions].deepLinkURLScheme = %@;", deepLinkURLScheme);
        }

        [FIRApp configure]; // Crashes here
        SEGLog(@"[FIRApp Configure]");
    }
    return self;
}
rodrijuarez commented 6 years ago

Another nice solution'd be react-native-analytics-segment-io Analytics setup to call the Promise.resolve whenever the library finishes also all the integrations initialisation, which'd be the expected behaviour