ionic-team / capacitor

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

PushNotification with data only not received on iPhone #2875

Closed kvowinckel closed 4 years ago

kvowinckel commented 4 years ago

What works:

I can send push notifications via FCM to my ionic app, as long as the message has next to data a notification as well. Both, on iOS and Android, the os notification is displayed when the app is in background. And in both, I can also work with the registered listener within the app to perform actions.

Server-side:

let message = {
    data: {key: value},
    notification: {
        title: title,
        body: subtitle
    },
    token: device
}

firebase_admin.messaging().send(message).catch(err => console.error(err));

App-side:

PushNotifications.addListener('pushNotificationReceived', 
      async (notification: PushNotification) => {

        alert(JSON.stringify(notification));
});

What does not work:

Now I also want to send a notification to the app, which is silently when the app is in the background, but triggers the registered listener, when the app is in foreground. Therefore, I am sending a data message via FCM (nit containing a notification). While this works in the Android App, nothing arrives in the iOS app.

let message = {
        data,
        token: device,
};
firebase_admin.messaging().send(message).catch(err => console.error(err));

I also tried to add

apns: {
    headers: { "apns-priority": "5", "apns-push-type": "background" },
    payload: { aps: { "content-available": 1 } }
}

without success.

Installed Dependencies:

@capacitor/electron not installed

@capacitor/cli 2.0.0

@capacitor/core 2.0.0

@capacitor/ios 2.0.0

@capacitor/android 2.0.0

XCode: iOS: 11.0

Ionic:

Ionic CLI : 6.7.0 Ionic Framework : @ionic/angular 5.0.7 @angular-devkit/build-angular : 0.803.26 @angular-devkit/schematics : 8.3.26 @angular/cli : 8.3.26 @ionic/angular-toolkit : 2.2.0

Capacitor:

Capacitor CLI : 2.0.0 @capacitor/core : 2.0.0

jcesarmobile commented 4 years ago

Capacitor uses APNS for push notifications on iOS and they work fine, if you are using FCM then you probably did something wrong, sorry, I can't help you with that.

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.