Handle remote notifications with ionic capacitor in angular (e.g. user taps on a push notification).
This is only implemented for iOS currently, to handle an issue with capacitor push notifications where pushNotificationActionPerformed
is not called on notification tap.
npm install cap-remote-plugin
npx cap sync
-
Handle remote notifications in your
AppDelegate.swift
file
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
print("on remote message called")
NotificationCenter.default.post(name:Notification.Name("OnRemoteMessage"), object: userInfo);
completionHandler(UIBackgroundFetchResult.newData)
}
- Listen for the event in your typescript
CapRemotePlugin.addListener(
'OnRemoteNotification',
(notification: PushNotificationSchema) => {
console.log('ON REMOTE NOTIFICATION');
console.log(notification);
},
);