0.0.3 • Published 4 years ago

cap-remote-plugin v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

cap-remote-plugin

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.

Install

npm install cap-remote-plugin
npx cap sync

Setup

  1. Enable remote notifs for your iOS project Background Modes Remote Notifs

  2. 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)
}
  1. Listen for the event in your typescript
CapRemotePlugin.addListener(
  'OnRemoteNotification',
  (notification: PushNotificationSchema) => {
    console.log('ON REMOTE NOTIFICATION');
    console.log(notification);
  },
);