phonegap / phonegap-plugin-push

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

on notification ios does not work? #2629

Open eros2187 opened 5 years ago

eros2187 commented 5 years ago

iOS 11

Cordova CLI version and cordova platform version

cordova --version     # e.g.7.1.0

Plugin version

2.2.3

Sample Push Data Payload

?php // Put your device token here (without spaces): $deviceToken = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

// Put your private key's passphrase here: $passphrase = 'xxxxxxxxxxxxxxxxx'; $pemfilename = 'xxxxxxxxxxxxxxx';

// SIMPLE PUSH $body['aps'] = array( 'alert' => array( 'title' => "You have a notification", 'body' => "Body of the message", "content-available" => 1 ), 'badge' => 1, 'sound' => 'default', ); // Create the payload body

////////////////////////////////////////////////////////////////////////////////

$ctx = stream_context_create(); stream_context_set_option($ctx, 'ssl', 'local_cert', $pemfilename); stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

$fp = stream_socket_client( 'ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx); // Open a connection to the APNS server if (!$fp) exit("Failed to connect: $err $errstr" . PHP_EOL); echo 'Connected to APNS' . PHP_EOL; $payload = json_encode($body); // Encode the payload as JSON $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload; // Build the binary notification $result = fwrite($fp, $msg, strlen($msg)); // Send it to the server if (!$result) echo 'Message not delivered' . PHP_EOL; else echo 'Message successfully delivered' . PHP_EOL; fclose($fp); // Close the connection to the server

Sample Code that illustrates the problem

push.on('notification', function(data) { // data.message, // data.title, // data.count, // data.sound, // data.image, // data.additionalData alert(JSON.stringify(data));

when app is closed and I receive a notification by clicking on the notification why not call on notification? where my mistake?

ghost commented 5 years ago

+1 I notice the same behaviour. In addiction in iOS >= 10.x, in iOS 9.3.3 all works fine. Troubling in the Console I've found a maybe related error:

default   15:38:20.018853 +0100    SpringBoard         High Priority Push: it.spindox.sisal.eurojackpot - App killed
errore     15:38:20.028339 +0100    SpringBoard         Could not load data at /var/mobile/Library/SpringBoard/PushStore/it.spindox.sisal.eurojackpot.pushstore
default   15:38:20.028517 +0100    SpringBoard         Saving notification list at /var/mobile/Library/SpringBoard/PushStore/it.spindox.sisal.eurojackpot.pushstore with 1 items

Since in the follow method is described a NSLog(@"Push Plugin didReceiveNotificationResponse: actionIdentifier %@, notification: %@", ....

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
         withCompletionHandler:(void(^)(void))completionHandler

I searched also for the Push Plugin didReceiveNotificationResponse: string but without any result found in the system log.

Also I add that to send push notification to the devices we use localytics with "cordova-localytics". I kwnown that this problem were not present in "phonegap-plugin-push" ~1.0.0.

eros2187 commented 5 years ago

+1 noto lo stesso comportamento. In aggiunta a iOS> = 10.x, in iOS 9.3.3 tutto funziona correttamente. Disturbo nella console Ho trovato un errore forse correlato:

default   15:38:20.018853 +0100    SpringBoard         High Priority Push: it.spindox.sisal.eurojackpot - App killed
errore     15:38:20.028339 +0100    SpringBoard         Could not load data at /var/mobile/Library/SpringBoard/PushStore/it.spindox.sisal.eurojackpot.pushstore
default   15:38:20.028517 +0100    SpringBoard         Saving notification list at /var/mobile/Library/SpringBoard/PushStore/it.spindox.sisal.eurojackpot.pushstore with 1 items

Poiché nel metodo seguente è descritto a NSLog(@"Push Plugin didReceiveNotificationResponse: actionIdentifier %@, notification: %@", ....

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
         withCompletionHandler:(void(^)(void))completionHandler

Ho cercato anche la Push Plugin didReceiveNotificationResponse:stringa ma senza alcun risultato trovato nel registro di sistema.

Inoltre aggiungo che per inviare notifiche push ai dispositivi usiamo localytics con "cordova-localytics". Ho saputo che questo problema non era presente in "phonegap-plugin-push" ~ 1.0.0.

how did you solve it? Is there a plugin version that works well with ios that tested?

martin-richter-uk commented 5 years ago

@BobCaSUaL

1) you kill the app completely 2) notification appears 3) on("notification") not called on tap on notification (so I cannot show the user, for example content from the notification).

Is that the problem solved in your pull request?

eros2187 commented 5 years ago

I SOLVED CREATING MESSAGE ARRAY WITH THIS FORMAT ADD content-available'=>true $msg = array ( 'title' => 'titolo', 'style' => "picture", //"inbox per tipo box email" o picture per foto 'message' => 'messaggio', 'notId' => "order-message",//raggruppare notifiche 'summaryText' => "test", 'image' => 'https://www.ekiconsult.com/wp-content/uploads/2014/06/test-img-500x500-1.png', 'picture' => 'https://www.ekiconsult.com/wp-content/uploads/2014/06/test-img-500x500-1.png', 'badge'=>0, 'content-available'=>true, //Must be present for Android 'url'=>'https://www.google.com', 'priority'=>'high', 'vibrationPattern'=>[2000, 1000, 500, 500],// vibrazione 'ledColor'=> [0, 248,176, 36];//led color

);

ghost commented 5 years ago

@BobCaSUaL

  1. you kill the app completely
  2. notification appears
  3. on("notification") not called on tap on notification (so I cannot show the user, for example content from the notification).

Is that the problem solved in your pull request?

@rychter yes, it is. On iOS only. In my environment Android seems to work.

martin-richter-uk commented 5 years ago

https://github.com/phonegap/phonegap-plugin-push/issues/2266 - My theory is katzer/cordova-plugin-local-notification is not the only plugin causing that problem. I believe there are other plugins that do the exact same thing. Today I will try to remove plugins one by one to figure out which one is it.

I have two projects - one with notifications only - works ok. The other is with notifications and lots of other plugins - on('notification') on coldstart does not work on ios, works on android.