@@ -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+
316334firebase . _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
333344firebase . _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