I'm building a Cordova hybrid application, which uses push notification plugin - https://github.com/phonegap/phonegap-plugin-push. For Android part I use gcm and for iOS I use APNs. Everything works with Android devices. I can send APN to server and it shows that everything is okay, but I can't get it on my iPhone device. I can get iPhone registration id and I send my notification directly to that device, but function, which is responsible for handling notification, doesn't react. I also tried to re-install the plugin, but that didn't help.
How I am receiving my notification in js:
var push = PushNotification.init({
"android": {
"senderID": "xx"
},
"ios": {"alert": "true", "badge": "true", "sound": "true"},
"windows": {}
});
push.on('registration', function(data) {
//I can get registration id here
alert(JSON.stringify(data));
});
push.on('notification', function(data) {
//this place doesn't work
alert("notification event");
alert(JSON.stringify(data));
});
push.on('error', function(e) {
alert("push error");
});
This is how I send my notification to server in php:
$deviceToken = 'xxx';
$passphrase = 'xx';
$message = 'My first push notification!';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
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);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
echo 'Connected to APNS' . PHP_EOL;
$body['aps'] = array(
'alert' => $message,
'sound' => 'default'
);
$payload = json_encode($body);
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg));
if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;
fclose($fp);
This outputs that 'Message successfully delivered'. Is there a chance that this doesn't work on iOS 9? (I have tested just on one device) Maybe there are some other ideas why it doesn't work?