I'm using phonegap-plugin-push to send push notifications to Android devices.
I'm trying to figure out how to send notification to iOs.
I'get token at client app same way as in Android:
var push = PushNotification.init({
android: {
senderID: "5993...475"
},
ios: {
alert: "true",
badge: true,
sound: 'false'
},
windows: {}
});
push.on('registration', function(data) {
$.ajax({
url: '/save-token/',
data: {token: data.registrationId},
success: function (json) {
}
});
});
After I get client's token, I try to send'em push notification:
$to = ModelGcmTokens::getInstance()->getToken($userId);
$API_KEY = 'AIzaS...HcEYC346zQ';
$message = array(
'data' => array(
'title' => ($title) ? $title : 'Test!',
'message' => $message
),
'to' => $to
);
$message = json_encode($message);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://gcm-http.googleapis.com/gcm/send");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $message);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization:key={$API_KEY}",
"Content-Type:application/json",
));
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
// further processing ....
if ($server_output == "OK") {
return true;
} else {
return false;
}
Google cloud messaging responds with InvalidRegistration error:
{"multicast_id":4701637331500989392,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
As I googled this error - it's said that I got client's token wrong. But I get it with excat same script as on Android. And it works on Android.
The only difference, that I see - is format of the token:
Can anyone tell me how do I get push plugin working on iOs? What's wrong with iOs token and how do I supposed to send messages to GCM, to be received by iOs?
Thanks a lot in advance for any advice. I'm really stuck.