0
我正在從php發送gcm推送通知給cordova應用程序。當用戶移動連接互聯網時,它運行良好。如果用戶手機沒有連接互聯網4小時,並在此期間我的服務器發送5通知。在與互聯網連接,用戶必須得到5丟失通知,但沒有得到任何人。我在cordova應用程序中使用phonegap-plugin-push 1.6.4「PushPlugin」提前致謝。無法獲取gcm推送通知
PHP代碼
$registrationIds = array($to);
$msg = array
(
'notId' => rand(1, 999999),
'message' => $message,
'title' => $title,
'vibrate' => 1,
'sound' => 1
);
$fields = array
(
'registration_ids' => $registrationIds,
'data' => $msg
);
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://android.googleapis.com/gcm/send');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
curl_close($ch);
科爾多瓦JS代碼
var push = PushNotification.init({"android": {"senderID": appsenderid, "alert": true, "badge": true, "sound": true},
"ios": {"alert": "true", "badge": "true", "sound": "true"}, "windows": {}});
push.on('registration', function (data) {
//alert(data.registrationId);
register_device(data.registrationId);
});
但我從未收到待處理通知 –