iOS Push Notifications not being received after Capacitor 2->3 and Ionic 5->6 Migration

We’ve migrated our Ionic/Angular app from Ionic 5 / Capacitor 2 to Ionic 6 / Capacitor 3 and are now finding that push Notifications are not being received on iOS - they work ok on Android. We use the Capacitor Push Notifications API.

If I install the last build we made prior to moving to Capacitor 3 and Ionic 6 the notifications are received again - so it’s not a server / certificate issue - it’s definitely something to do with the app migration.

I’ve gone over the Capacitor 3 migration instructions again and have double-checked that I have made the correct changes to the AppDelegate.swift file.

Anyone else had issues with iOS Push Notifications after migrating or have any good suggestions for what I might have done wrong?

I’m running fine on Capacitor 3 and Ionic 6. Does your AppDelegate.swift look like the code below (reference)? They recently updated the guide to make it clearer (commit) that you do need the FCM token and not the raw iOS APN token.

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  Messaging.messaging().apnsToken = deviceToken
  Messaging.messaging().token(completion: { (token, error) in
    if let error = error {
        NotificationCenter.default.post(name: .capacitorDidFailToRegisterForRemoteNotifications, object: error)
    } else if let token = token {
        NotificationCenter.default.post(name: .capacitorDidRegisterForRemoteNotifications, object: token)
    }
  })
}

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
  NotificationCenter.default.post(name: .capacitorDidFailToRegisterForRemoteNotifications, object: error)
}
1 Like

Mine doesn’t look exactly like that. I have:


func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        NotificationCenter.default.post(name: Notification.Name(CAPNotifications.DidRegisterForRemoteNotificationsWithDeviceToken.name()), object: deviceToken)
     }

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
        NotificationCenter.default.post(name: Notification.Name(CAPNotifications.DidFailToRegisterForRemoteNotificationsWithError.name()), object: error)
     }

That is probably the problem then. By default it gives you the APN token but you need the FCM token in order for it to work with Firebase. I would give the recommended code a try.

1 Like

Yeah I was just reading up on it. Thanks very much for that, I will give it a try. If this does work then - apart from thanks again! - how would I have found that out (other than asking in this forum!) ?? Is it documented anywhere else?

Good question! I followed the guide before it was updated. Before it said if you want the FCM token use the code I mentioned. Since I didn’t know I needed the FCM token, I didn’t use the code. For me it was just trial and error until I got it working after realizing Firebase does in fact need the FCM token.

It seems the actual plugin documentation should be updated. Maybe I’ll submit a pull request :slight_smile:

UPDATE: I created a PR here.

1 Like

Thank you thank you thank you - all working now!

1 Like

You’re welcome! Glad I could help.