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: pushNotificationActionPerformed listener not firing on iOS #2199

Closed nicdichiara closed 4 years ago

nicdichiara commented 4 years ago

Bug Report

Capacitor Version

npx cap doctor output:

Latest Dependencies:

@capacitor/cli: 1.3.0

@capacitor/core: 1.3.0

@capacitor/android: 1.3.0

@capacitor/ios: 1.3.0

Installed Dependencies:

@capacitor/cli 1.2.1

@capacitor/core 1.2.1

@capacitor/android 1.3.0

@capacitor/ios 1.3.0

Affected Platform(s)

Current Behavior

When a notification comes in, and it is clicked, the app opens as expected, but the pushNotificationActionPerformed listener does not fire. For both iOS and Android we immediately alert to show that the listener has triggered. On Android it alerts, and on iOS it doesn't, leading us to believe there is an issue with the iOS pushNotificationActionPerformed implementation.

We are experiencing the same results for pushNotificationReceived as well.

We are receiving notifications on both iOS and Android properly, so we do not think there are any issues with our APN config or server-side messaging functions.

Expected Behavior

We expect an alert on iOS when the app is launched from a notification, calling the pushNotificationActionPerformed listener.

Sample Code or Sample Application Repo

// DIRECTLY FROM CAPACITOR TUTORIAL: 
// https://capacitor.ionicframework.com/docs/guides/push-notifications-firebase/

export class HomePage implements OnInit {

ngOnInit() {
    console.log('Initializing HomePage');

    // Register with Apple / Google to receive push via APNS/FCM
    PushNotifications.register();

    // On success, we should be able to receive notifications
    PushNotifications.addListener('registration', 
      (token: PushNotificationToken) => {
        alert('Push registration success, token: ' + token.value);
      }
    );

    // Some issue with our setup and push will not work
    PushNotifications.addListener('registrationError', 
      (error: any) => {
        alert('Error on registration: ' + JSON.stringify(error));
      }
    );

    // Show us the notification payload if the app is open on our device
    PushNotifications.addListener('pushNotificationReceived', 
      (notification: PushNotification) => {
        alert('Push received: ' + JSON.stringify(notification));
      }
    );

    // Method called when tapping on a notification
    PushNotifications.addListener('pushNotificationActionPerformed', 
      (notification: PushNotificationActionPerformed) => {
        alert('Push action performed: ' + JSON.stringify(notification));
      }
    );
}

From the server:

let message = {
          notification: {
            title: `Customer Message`,
            body: msg.body,
          },
          data: {
            type: MSGTYPE.msg,
            oid: oid,
            title: `Customer Message`,
            body: msg.body,
          },
          android: {
            ttl: 900 * 1000, // 15 min in milliseconds
            priority: 'high',
            notification: {
              sound: 'default',
              color: '#f45342',
            },
          },
          apns: {
            payload: {
              aps: {
                badge: 1,
                sound: 'default',
              },
            },
          },
          token: userToken,
        };

Reproduction Steps

We implemented the boiler-plate example code from https://capacitor.ionicframework.com/docs/guides/push-notifications-firebase/ on a blank ionic 4 capacitor application. We send the above message packet and the pushNotificationActionPerformed listener does not fire on iOS.

Other Technical Details

npm --version output: 6.9.0 node --version output: v10.16.3 pod --version output (iOS issues only): 1.8.4

Other Information

We have been testing on iOS 13+ devices.

nikmartin commented 4 years ago

We are seeing this in two of our apps as well. Push works fine on Android with app in FG or BG, but only in BG on iOS, and neither pushNotificationReceived nor pushNotificationActionPerformed are firing.

Livijn commented 4 years ago

For me, writing to the file CAPUNUserNotificationCenterDelegate.swift worked. Just adding print("pushNotificationReceived") here fixes it for me. I guess it's Xcode caching the files somehow.

jcesarmobile commented 4 years ago

That guide wasn't very good and had some problems, it got updated recently, but requires @capacitor/ios 1.4.0. Please, try updating to @capacitor/ios 1.4.0 and make sure you are getting the latest version of the guide.

andreasaphilo commented 3 years ago

For me, writing to the file CAPUNUserNotificationCenterDelegate.swift worked. Just adding print("pushNotificationReceived") here fixes it for me. I guess it's Xcode caching the files somehow.

Can you provide the solution on the "here" link with the push notifications?

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.