I'm using the push notification plugin on my application and the call back is not working PushNotifications.addListener( 'registration', ( token: PushNotificationToken ) => ...
Has anyone experienced something like this before?
Found the issue... there is a block of code that needs to be changed on the AppDelegate.swift
and Podfile
files.
AppDelegate.swift: Change this:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
NotificationCenter.default.post(name: Notification.Name(CAPNotifications.DidRegisterForRemoteNotificationsWithDeviceToken.name()), object: deviceToken)
}
for this:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
InstanceID.instanceID().instanceID { (result, error) in
if let error = error {
NotificationCenter.default.post(name: Notification.Name(CAPNotifications.DidFailToRegisterForRemoteNotificationsWithError.name()), object: error)
} else if let result = result {
NotificationCenter.default.post(name: Notification.Name(CAPNotifications.DidRegisterForRemoteNotificationsWithDeviceToken.name()), object: result.token)
}
}
}
PodFile:
Add under capacitor_pods:
pod 'Firebase/Messaging'