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

Commit ec116aa

Browse files
Merge pull request #519 from rhrn/fix-notificationsAfterKilling
#499 Fix notifications after killing
2 parents 1cc6449 + e85d869 commit ec116aa

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

firebase.ios.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -313,21 +313,32 @@ firebase._processPendingNotifications = function () {
313313
}
314314
};
315315

316+
firebase._messagingConnectWithCompletion = function () {
317+
return new Promise(function (resolve, reject) {
318+
319+
FIRMessaging.messaging().connectWithCompletion(function (error) {
320+
321+
if (error) {
322+
// this is not fatal and it scares the hell out of ppl so not logging it
323+
// console.log("Firebase was unable to connect to FCM. Error: " + error);
324+
return reject(error);
325+
}
326+
327+
firebase._messagingConnected = true;
328+
resolve();
329+
});
330+
331+
});
332+
};
333+
316334
firebase._onTokenRefreshNotification = function (token) {
317335
firebase._pushToken = token;
318336

319337
if (firebase._receivedPushTokenCallback) {
320338
firebase._receivedPushTokenCallback(token);
321339
}
322340

323-
FIRMessaging.messaging().connectWithCompletion(function (error) {
324-
if (error) {
325-
// this is not fatal and it scares the hell out of ppl so not logging it
326-
// console.log("Firebase was unable to connect to FCM. Error: " + error);
327-
} else {
328-
firebase._messagingConnected = true;
329-
}
330-
});
341+
firebase._messagingConnectWithCompletion();
331342
};
332343

333344
firebase._registerForRemoteNotificationsRanThisSession = false;
@@ -455,6 +466,10 @@ function prepAppDelegate() {
455466

456467
firebase._addObserver(UIApplicationDidBecomeActiveNotification, function (appNotification) {
457468
firebase._processPendingNotifications();
469+
470+
if (!firebase._messagingConnected) {
471+
firebase._messagingConnectWithCompletion();
472+
}
458473
});
459474

460475
firebase._addObserver(UIApplicationDidEnterBackgroundNotification, function (appNotification) {

0 commit comments

Comments
 (0)