0

I am sending gcm push notification from php to cordova app .It works well when user mobile connected with internet. If user mobile is not connected with internet for 4 hours and during that time my server is sending 5 notification .On connecting with internet, user must get 5 missing notification but not getting any of them. I am using phonegap-plugin-push 1.6.4 "PushPlugin" in cordova app Thanks in advance .

PHP Code

            $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);

Cordova JS Code

      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);
});

1 Answers1

0

Maybe the message just got delayed. Be noted that it can take up to 15 minutes to the message to arrive when device reconnects to the internet. If the device is offline, it would receive all the pending notifications once reconnected. In case of wrong Registration ID or any other errors, Google returns a corresponding response.

Check if this thread and tutorial will help.

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59