ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web ⚡️
https://capacitorjs.com
MIT License
11.46k stars 977 forks source link

bug: ActionPerformed object miss the PushNotificationSchema object #4934

Closed TheNemus closed 2 years ago

TheNemus commented 2 years ago

Bug Report

Capacitor Version

Latest Dependencies:

@capacitor/cli: 3.1.2 @capacitor/core: 3.1.2 @capacitor/android: 3.1.2 @capacitor/ios: 3.1.2

Installed Dependencies:

@capacitor/cli: 3.1.1 @capacitor/android: 3.1.1 @capacitor/ios: 3.1.2 @capacitor/core: 3.1.1

[success] iOS looking great! 👌 [success] Android looking great! 👌

Platform(s)

Android 8 (real device) Android 11 (simulator)

Current Behavior

After receiving a push notification, event pushNotificationReceived gives a pushNotificationSchema object: image with 'title', 'body' and 'data' fields When I tap the notification, pushNotificationActionPerformed gives an ActionPerformed object whose notification fields miss all these fields, giving the app no chance to know what to do: image

Expected Behavior

Having the notification object both from pushNotificationReceived event and pushNotificationActionPerformed event

Code Reproduction

    // Show us the notification payload if the app is open on our device
    PushNotifications.addListener('pushNotificationReceived',
      (notification: PushNotificationSchema) => {
        console.log('new notif', notification);
      }
    );

    // Method called when tapping on a notification
    PushNotifications.addListener('pushNotificationActionPerformed',
      (action: ActionPerformed) => {
        console.log('new notif action', action);
      }
    );

Other Technical Details

This code perfectly works on iOS 14.5 (simulator)

npm --version output: 6.13.4

node --version output: 12.14.1

jcesarmobile commented 2 years ago

When your app is backgrounded or closed the OS takes those fields to display the notification, but don't pass them to the app when the notification is tapped

TheNemus commented 2 years ago

@jcesarmobile actually, it doesn't work even with the app in foreground. Anyway, this should be noted in plugin documentation.

Is any other way to recover the notification data?

ionitron-bot[bot] commented 1 year ago

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.