带有iOs的Phonegap推送通知插件

我正在使用phonegap-plugin-push将推送通知发送到Android设备。

我想弄清楚如何发送通知给IO。

我已在https://developers.google.com/mobile/add?platform=ios&cntapi=gcm&cnturl=https:%2F%2Fdevelopers.google.com%2Fcloud-messaging%2Fios%2Fclient&cntlbl=Continue%20Adding%20GCM%注册20Support&%3Fconfigured%3Dtrue

我在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) { } }); }); 

当我得到客户的令牌后,我尝试发送推送通知:

 $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云消息响应InvalidRegistration错误:

 {"multicast_id":4701637331500989392,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]} 

当我search这个错误 – 据说,我得到客户的标记是错误的。 但是我喜欢和Android一样的脚本。 它适用于Android。

唯一的区别,我看到 – 是令牌的格式:

在这里输入图像说明

任何人都可以告诉我如何获得推送插件iOs工作? iOs令牌有什么问题,我应该如何向GCM发送消息,由iOs接收?

提前感谢您的任何build议。 我真的被卡住了

你调用init方法的方式是从APNS而不是GCM请求注册ID。 如果您阅读phonegap-plugin-push存储库上的iOS上的GCM文档,您将看到init需要像这样调用:

 var push = PushNotification.init({ android: { senderID: "5993...475" }, ios: { senderID: "5993...475", gcmSandbox: true, alert: "true", badge: true, sound: 'false' }, windows: {} }); 

如果iOS选项有一个senderID ,它将注册到GCM。

另外,我注意到在对其中一个评论的回复中,您不知道APNS上的production环境和development环境之间的区别。 那么,你真的需要阅读这个。 在iOS设备上,APNS环境因productiondevelopment环境而异。 如果您将您的应用设置为development并通过production发送,则永远不会到达您的设备。

现在你可能会问为什么我在谈论APNS。 这是因为当你在iOS上使用GCM时,你会发送你的推送消息给GCM,然后它将把你的消息转发到APNS服务器,最后到你的设备。