2017-01-18 145 views
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); 
}); 

回答

0

也許消息剛剛推遲。請注意,當設備重新連接到互聯網時,最長可能需要15分鐘到message to arrive。如果設備處於脫機狀態,則會在重新連接後收到所有待處理的通知。如果註冊ID錯誤或其他錯誤,Google會返回相應的回覆。

檢查這個threadtutorial會有幫助。

+0

但我從未收到待處理通知 –