@@ -90,6 +90,7 @@ export function registerForPushNotifications(options?: MessagingOptions): Promis
9090 }
9191 } ) ;
9292}
93+
9394export function unregisterForPushNotifications ( ) : Promise < void > {
9495 return new Promise ( ( resolve , reject ) => {
9596 try {
@@ -152,15 +153,19 @@ export function addOnPushTokenReceivedCallback(callback) {
152153}
153154
154155export function addBackgroundRemoteNotificationHandler ( appDelegate ) {
155- if ( typeof ( FIRMessaging ) === "undefined" ) {
156- appDelegate . prototype . applicationDidRegisterForRemoteNotificationsWithDeviceToken = ( application : UIApplication , deviceToken : NSData ) => {
156+ appDelegate . prototype . applicationDidRegisterForRemoteNotificationsWithDeviceToken = ( application : UIApplication , deviceToken : NSData ) => {
157+ if ( typeof ( FIRMessaging ) !== "undefined" ) {
158+ // make sure Firebase has the latest APNs token (issue #982)
159+ FIRMessaging . messaging ( ) . APNSToken = deviceToken ;
160+ } else {
161+ // if Firebase Messaging isn't used, the developer cares about the APNs token, so pass it to the app
157162 const token = deviceToken . description . replace ( / [ < > ] / g, "" ) ;
158163 _pushToken = token ;
159164 if ( _receivedPushTokenCallback ) {
160165 _receivedPushTokenCallback ( token ) ;
161166 }
162- } ;
163- }
167+ }
168+ } ;
164169
165170 appDelegate . prototype . applicationDidReceiveRemoteNotificationFetchCompletionHandler = ( app , notification , completionHandler ) => {
166171 // Pass notification to auth and check if they can handle it (in case phone auth is being used), see https://firebase.google.com/docs/auth/ios/phone-auth
@@ -561,9 +566,9 @@ class UNUserNotificationCenterDelegateImpl extends NSObject implements UNUserNot
561566 const userInfoJSON = firebaseUtils . toJsObject ( userInfo ) ;
562567
563568 if ( _showNotificationsWhenInForeground || // Default value, in case we always want to show when in foreground.
564- userInfoJSON [ "gcm.notification.showWhenInForeground" ] === "true" || // This is for FCM, ...
565- userInfoJSON [ "showWhenInForeground" ] === true || // ...this is for non-FCM...
566- ( userInfoJSON . aps && userInfoJSON . aps . showWhenInForeground === true ) // ...and this as well (so users can choose where to put it).
569+ userInfoJSON [ "gcm.notification.showWhenInForeground" ] === "true" || // This is for FCM, ...
570+ userInfoJSON [ "showWhenInForeground" ] === true || // ...this is for non-FCM...
571+ ( userInfoJSON . aps && userInfoJSON . aps . showWhenInForeground === true ) // ...and this as well (so users can choose where to put it).
567572 ) {
568573 // don't invoke the callback here, since the app shouldn't fi. navigate to a new page unless the user pressed the notification
569574 completionHandler ( UNNotificationPresentationOptions . Alert | UNNotificationPresentationOptions . Sound | UNNotificationPresentationOptions . Badge ) ;
0 commit comments