Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 4cec656

Browse files
Only override iOS AppDelegate's applicationDidFinishLaunchingWithOptions if we really have to #1230
1 parent acdbaa1 commit 4cec656

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

src/firebase.ios.ts

+29-18
Original file line numberDiff line numberDiff line change
@@ -58,29 +58,40 @@ firebase.areNotificationsEnabled = firebaseMessaging.areNotificationsEnabled;
5858

5959
firebase.functions = firebaseFunctions;
6060

61+
NSNotificationCenter.defaultCenter.addObserverForNameObjectQueueUsingBlock(
62+
UIApplicationDidFinishLaunchingNotification,
63+
null,
64+
NSOperationQueue.mainQueue,
65+
appNotification => {
66+
if (!firebase._configured) {
67+
firebase._configured = true;
68+
if (typeof (FIRApp) !== "undefined") {
69+
FIRApp.configure();
70+
}
71+
}
72+
});
73+
6174
firebase.addAppDelegateMethods = appDelegate => {
6275
// we need the launchOptions for this one so it's a bit hard to use the UIApplicationDidFinishLaunchingNotification pattern we're using for other things
63-
appDelegate.prototype.applicationDidFinishLaunchingWithOptions = (application, launchOptions) => {
64-
if (!firebase._configured) {
65-
firebase._configured = true;
66-
if (typeof (FIRApp) !== "undefined") {
67-
FIRApp.configure();
76+
// however, let's not override 'applicationDidFinishLaunchingWithOptions' if we don't really need it:
77+
if (typeof (FIRMessaging) !== "undefined" || useExternalPushProvider || typeof (FBSDKApplicationDelegate) !== "undefined") {
78+
appDelegate.prototype.applicationDidFinishLaunchingWithOptions = (application, launchOptions) => {
79+
// If the app was terminated and iOS is launching it in result of a push notification tapped by the user, this will hold the notification data.
80+
if (launchOptions) {
81+
const remoteNotification = launchOptions.objectForKey(UIApplicationLaunchOptionsRemoteNotificationKey);
82+
if (remoteNotification) {
83+
firebaseMessaging.handleRemoteNotification(application, remoteNotification);
84+
}
6885
}
69-
}
7086

71-
// If the app was terminated and iOS is launching it in result of a push notification tapped by the user, this will hold the notification data.
72-
if (launchOptions) {
73-
const remoteNotification = launchOptions.objectForKey(UIApplicationLaunchOptionsRemoteNotificationKey);
74-
if (remoteNotification) {
75-
firebaseMessaging.handleRemoteNotification(application, remoteNotification);
87+
// Firebase Facebook authentication
88+
if (typeof (FBSDKApplicationDelegate) !== "undefined") {
89+
FBSDKApplicationDelegate.sharedInstance().applicationDidFinishLaunchingWithOptions(application, launchOptions);
7690
}
77-
}
78-
// Firebase Facebook authentication
79-
if (typeof (FBSDKApplicationDelegate) !== "undefined") {
80-
FBSDKApplicationDelegate.sharedInstance().applicationDidFinishLaunchingWithOptions(application, launchOptions);
81-
}
82-
return true;
83-
};
91+
92+
return true;
93+
};
94+
}
8495

8596
// there's no notification event to hook into for this one, so using the appDelegate
8697
if (typeof (FBSDKApplicationDelegate) !== "undefined" || typeof (GIDSignIn) !== "undefined" || typeof (FIRInvites) !== "undefined" || typeof (FIRDynamicLink) !== "undefined") {

src/messaging/messaging.ios.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,7 @@ function _processPendingActionTakenNotifications() {
541541
}
542542

543543
function _addObserver(eventName, callback) {
544-
const queue = iOSUtils.getter(NSOperationQueue, NSOperationQueue.mainQueue);
545-
return iOSUtils.getter(NSNotificationCenter, NSNotificationCenter.defaultCenter).addObserverForNameObjectQueueUsingBlock(eventName, null, queue, callback);
544+
return NSNotificationCenter.defaultCenter.addObserverForNameObjectQueueUsingBlock(eventName, null, NSOperationQueue.mainQueue, callback);
546545
}
547546

548547
// see https://developer.apple.com/reference/usernotifications/unusernotificationcenterdelegate?language=objc

0 commit comments

Comments
 (0)