phonegap / phonegap-plugin-push

Register and receive push notifications
MIT License
1.94k stars 1.91k forks source link

ON(NOTIFICATION) IOS NOT WORKING IN BACKGROUND #2380

Open jakute opened 6 years ago

jakute commented 6 years ago

Expected Behaviour

When the app is closed and a push arrives the user clicks on the push then the app starts and appears the new notification

Actual Behaviour

When the app is closed and a push arrives the user clicks on the push then the app starts and shows nothing.

Reproduce Scenario (including but not limited to)

It works perfect in android, I use php server to send the push. I tried the FCM page and has the same issue. Today I have tried with "pusher" and still the same issue.

Platform and Version (eg. Android 5.0 or iOS 9.2.1)

IOS 9.0 on and IPAD (that doesn't allow iOS 10 :(. )

Cordova CLI version and cordova platform version

cordova --version                                    8.0

Plugin version

cordova plugin version. grep phonegap-plugin-push                       2.2.2

Sample Push Data Payload

  $arrayToSend = array(
                 'registration_ids' => $registrationIds,
                 "content-available" => 1,
                 "mutable_content" => true,
                 'priority'=>'high',
                 'notification'=>array('title' =>$title ,'text' => $message,'vibrate' => 1,'sound' => 1,"notId" => intval($correlativo) )
               );

Sample Code that illustrates the problem

pushsetup() {
const options: PushOptions = {
android: {
//senderID: 'XXXXXXXXXXXX'
icon:'./assets/ima/logo'
},
ios: {
alert: 'true',
badge: true,
sound: 'true',
},
windows: {}
};
const pushObject: PushObject = this.push.init(options);
pushObject.setApplicationIconBadgeNumber(0);
//pushObject.clearAllNotifications();
pushObject.on('notification').subscribe((notification: any) => {
if(notification.additionalData.foreground){
var notId = notification.additionalData['gcm.notification.notId'];
var notTile = notification.title;
var notMensage = notification.message;
console.log(">>>>>>>>> mensaje 1 >>>>>>>>>>>");
console.log(notification);
var notFecha = this.fecha.getDate() + "/" + (this.fecha.getMonth() +1) + "/" + this.fecha.getFullYear(); 
var notHora = this.pushHora.getHours()+":"+this.pushHora.getMinutes();
// id - id_inico - visto - fecha -hora - titulo - descipcion
this.guardarMensaje("no",notId,notFecha,notHora,notTile,notMensage);
this.muestraDatos();
pushObject.clearAllNotifications();
pushObject.finish();
}else{
var notId = notification.additionalData['gcm.notification.notId'];
var notTile = notification.title;
var notMensage = notification.message;
console.log(">>>>>>>>< mensaje 2 >>>>>>>>>>< ");
console.log(notification);
var notFecha = this.fecha.getDate() + "/" + (this.fecha.getMonth() +1) + "/" + this.fecha.getFullYear(); 
var notHora = this.pushHora.getHours()+":"+this.pushHora.getMinutes();
// id - id_inico - visto - fecha -hora - titulo - descipcion
this.guardarMensaje("no",notId,notFecha,notHora,notTile,notMensage);
this.muestraDatos();
pushObject.clearAllNotifications();
}
this.muestraDatos();
pushObject.clearAllNotifications();
pushObject.finish();
});

Thanks in advance.

macdonst commented 6 years ago

@jakute it's probably a race condition where the on('notification') handler is not setup before the push is delivered to the starting app.

jakute commented 6 years ago

Thanks for the reply!! But it the same code for android and for iOS .... but with all the plugin for iOS (cocoa pods and iOS certificate). I don't know what is could be wrong maybe the content-available is not doing his work?. Also I see today that when I send throw the portal of FCM with the parameter content-available=1 it appears the same issue when is in background. Sorry for my English.

edmondchui commented 6 years ago

Looks like a duplicate of #2266

jakute commented 6 years ago

But I don't use katzer, why is a duplicate? don't understand that. I have tried many things but nothing works it seems like content-available is never process :(

edmondchui commented 6 years ago

Have you tried to put "content-available" => 1 inside your notification object? According to the Apple documentation, "content-available" => 1 should be put inside aps hash

jakute commented 6 years ago

yes I have tried that and the error continues

macdonst commented 6 years ago

@jakute when sending via FCM on iOS the payload needs to be a bit different. On iOS we strictly follow the FCM server ref as the code we use to receive the notification comes straight from Google.

So content-available: 1 becomes content_available: true.

Please try:

  $arrayToSend = array(
                 'registration_ids' => $registrationIds,
                 "content_available" => false,
                 "mutable_content" => true,
                 'priority'=>'high',
                 'notification'=>array('title' =>$title ,'text' => $message,'vibrate' => 1,'sound' => 1,"notId" => intval($correlativo) )
               );
jakute commented 6 years ago

@macdonst we just try that with false like you put it and true... but nothing works the push arrive bu when we click en the push or the app it doesn't show the notification :(

edmondchui commented 6 years ago

It could well be some formatting issue when sending from FCM to APNS. Can you try to use APNS alone to isolate the issue? It works for me as I'm sending directly via APNS.

martin-richter-uk commented 5 years ago

++

Ruchika19021995 commented 4 years ago

Hii,

Can anyone please tell me is this issue is resolved?

my Payload:

{ "priority": "high", "to": "dzAlPJvg-oM:APA91bHRNKM-6aHNnPFgDW3zC1ikVxxRJCrs1MVKZx5s3nRW29cXD52DpFsSYlN73wFPBtYppsW-nv-p_-grnpU2kFEDAUjwtUjP_VUrhJEnJPP7KAvCnqIc4polrRo-ZJfCljs9XLXx", "data": { "payload": { "pushType": 7, "title": "Title", "description": "Message", "source": "https://www.google.com.mx/" } }, "notification": { "title": "Title", "body": "Message" } }

initializeFCM() { const options: PushOptions = { android: {}, ios: { alert: 'true', badge: true, sound: 'false' }, windows: {}, browser: { pushServiceURL: 'http://push.api.phonegap.com/v1/push' } }

const pushObject: PushObject = this.push.init(options);

pushObject.on('notification').subscribe((notification: any) => { console.log('Received a notification', notification); if (!notification.additionalData.foreground) { var firstName = notification.additionalData.firstName; var lastName = notification.additionalData.lastName; var modifiedtime = notification.additionalData.modifiedTime; var username = notification.additionalData.userName; if (notification.additionalData.groupId) { var groupId = notification.additionalData.groupId; this.navigateToGroupUserChat(parseInt(groupId)); } else { this.navigateToOneToOneUserChat(firstName, lastName, username, modifiedtime); } } });

pushObject.on('registration').subscribe((registration: any) => { console.log('Device registered', registration); this.registerToken(registration.registrationId); });

pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error)); }

I am new in ionic please help me I am stuck in that issue more than 3 weeks kindle help me