Closed bull-xu closed 2 years ago
I see this problem also, when integrating Firebase DynamicLinks, as of version 2.4. As far as I can tell, it renders the integration unusable in any app that wants to use DynamicLinks. The fix above does appear to work, although I haven't verified whether there are other side effects.
@gpitfield I have discovered some side effects of my fix, so for you and others who want to use it, please note that the dynamic links will not work if starting the app from the cold state. This is because the fix delays the Firebase setup (namely the moment when [FIRApp configure]
is called). So when starting from cold, returning true
from ...didFinishLaunchingWithOptions
the ...application: UIApplication, continue userActivity: NSUserActivity, restorationHandler...
will be called, but at this time the Firebase SDK is not configured properly, so DynamicLinks.dynamicLinks().handleUniversalLink(url)
will return false and your callback will never be called.
I have patched this for myself by posting a notification from line 22 of SEGFirebaseIntegration
but this is more a hack than anything else. The proper fix should be to actually run the integration setup code on the main queue for the integrations that need this.
I also use the swizzling for fixing this issue:
Call FirebaseApp.exchange()
before the SegmentAnalytics(apiKey: apiKey, factories: factories)
then the FirebaseApp.configure()
will be called in the main thread.
extension FirebaseApp {
class func exchange() {
let origin = #selector(configure as () -> Void)
let with = #selector(myConfigure)
exchangeMethod(origin, with: with)
}
@objc
class func myConfigure() {
DispatchQueue.main.async {
myConfigure()
}
}
class func exchangeMethod(_ originalSelector: Selector, with overriddenSelector: Selector) {
guard
let originalMethod = class_getClassMethod(self, originalSelector),
let overriddenMethod = class_getClassMethod(self, overriddenSelector) else {
return
}
method_exchangeImplementations(originalMethod, overriddenMethod)
}
}
Another thing to be considered: Because the Segment will have a remote call to fetch the configuration setting options before the FirebaseApp.configure()
got called. Before that, the FirebaseApp.app() is always nil, if you want to use any feature of it, you need to wait for the remote call return and configure
being called. There is a notification we can use to detect this: FIRAppReadyToConfigureSDKNotification.
@briemcnally, maybe you could add some input on this issue?
In my Firebase project, I enable the Firebase/Messaging feature.
When the
SEGIntegrationsManager
tries to create the Firebase integration after fetching the settings (in a background thread), theupdateIntegrationsWithSettings
will use the same background thread to create each integration in the factories list.Hence the
SEGFirebaseIntegration
initWithSettings method is called from the background thread, which the[FIRApp configure]
will try to access the shared UIApplication's delegate, causing the Xcode 10 complains the error:I would avoid this error by modifying the SEGFirebaseIntegrationFactory's createWithSettings method like this:
What else I can do to prevent this error without modifying this lib's source?