quickstart-ios: APNS stops working on FCM Token Refresh

I’m having a big problem:

When I install the app and run the app for the first time, both the APNS and FCM notifications work ok. I can send Push Notifications via FCM and they’re received via FCM and APNS with no problem. When the FCM token is updated though, I stop receiving Notifications through the method didReceiveRemoteNotification at all, and am only able to receive messages through the (received remoteMessage: MessagingRemoteMessage) - that said, the Notification dictionary of my push isn’t read as a APNS. I haven’t disabled FCM’s swizzling, here’s the code I use for setting up Push Notifications:

func setupUserNotifications(application: UIApplication) {
        if #available(iOS 10.0, *) {
            let authOptions : UNAuthorizationOptions = [.alert, .badge, .sound]
            UNUserNotificationCenter.current().requestAuthorization(
                options: authOptions, completionHandler: {_,_ in })
            
            // For iOS 10 display notification (sent via APNS)
            UNUserNotificationCenter.current().delegate = self
            // For iOS 10 data message (sent via FCM)
            Messaging.messaging().delegate = self
            
        } else {
            // Fallback on earlier versions
            let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
            
            application.registerUserNotificationSettings(settings)
        }
        
        application.registerForRemoteNotifications()
        
        FirebaseApp.configure()
        
        if let token = Messaging.messaging().fcmToken() {
            connectToFcm(token)
        }
    }

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 5
  • Comments: 26 (5 by maintainers)

Most upvoted comments

I have exactly the same issue… Started happening after updating Firebase to version 4 and using the new p8 file.

What’s maybe of interest is, after the token is changed, I can still send push notifications to the device with the previous old token, even though Firebase is reporting a completely new token. Sending to the new token gives me a success response on the sender side, but the message is never received.

I’ve spent the whole day searching on why our notifications are not delivered after calling deleteIdWithHandler and it turns out the APN Token is not automatically passed when a new ID is requested/generated. Thus to solve this, thanks to all the comments here, we call UIApplication.shared.registerForRemoteNotifications() so the APN Token gets refreshed and Firebase notifications start working again. I think just by fetching and setting the APN token on the Messaging SDK would do the trick, but we decided to keep it clean and let the method swizzling take care of it.

I think a warning should be added somewhere in the documentation to let the users know they need to manually refresh the APN Token after deleting the instance ID.

Seems like the issue only happens when we delete the token and then kill the app.

This is because FIRMessaging fails to get access to APNS token after the app is killed and then restarted.

Solution: We need to somehow call [RCTSharedApplication() registerForRemoteNotifications] some time after the app restarts. If you’re using firebase-react-native, make sure to call firebase.messaging().ios.registerForRemoteNotifications() some time after app restarts

I am facing this issue not receiving notification after fcm token refresh.

I am using Firebase 5.15. I try in latest but didn’t work.

Any one have solution ?

I have this issue as well - I get a new token but pushes don’t work on update

I’m facing this issue too, old token is still working though. Fix anyone ?

Hi, we have the same issue and for us it is quite important.

Our App has a function to reset all private data. This is where we delete the token. If we do not do this, we fear that users will delete their private data, give their phone to someone else, who then gets messages meant for the prior owner. We believe that this presents a significant legal and reputation risk here in the EU. We are currently looking into workarounds, which might delay us launching, so it would be much appreciated if this could be fixed soon.

I’m deleting the ID as a means of testing something that eventually will happen naturally.

Yes i’m triggering FCM token update by deleting FIRInstanceID.

[[FIRInstanceID instanceID]deleteIDWithHandler:^(NSError * _Nullable error) {
    NSLog(@"%@", error.description);
    
}];

What is interesting same technique is used on Android, and notifications do not stop to work.