-2

I am trying to send push notification using cakephp but push notification are not sent. Now a days GCM id looks different is google change something in push notification process for eg (fRAvDRuNUU8:APA91bHvSGxi4AVPx2wGTFWb7OyAPPvXoIAcT). Every time I get a json which is below give:

 {
       "multicast_id": 5873180458565135923,
       "success": 0,
       "failure": 1,
       "canonical_ids": 0,
       "results": [
         {
           "error": "NotRegistered"
         }
     ]
 }

I tried so many code from internet but every time I get the same result. The code I am using is working on so many other application perfectly. Below is my code:

`    public function sendMessageAndroid($registatoin_ids, $message){
     $url = 'https://android.googleapis.com/gcm/send';
     $apiKey = "AIzaSyBf5vaONLbMyGdDoOEeC_MTTh9x1G4Qm-4";
     $fields = array(
        'registration_ids' => $registatoin_ids,//here my gcm id come in //array form array($device_id)
        'data' => $message,//this is my message //$send_message['m']=array('msg'=>$message,'type'=>'chat');
    );  
    $headers = array(
        'Authorization: key=' . $apiKey,
        'Content-Type: application/json'
    );   
    $ch = curl_init();      
    curl_setopt($ch, CURLOPT_URL, $url);
    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);
    if ($result === FALSE) {
        //die('Curl failed: ' . curl_error($ch));
    }        
   curl_close($ch);
   return $result;
}`

I tried everything with no luck. Please help.

Alessandro Cuttin
  • 3,822
  • 1
  • 30
  • 36
Arjun Choudhary
  • 203
  • 3
  • 16
  • Possible duplicate of [GCM 'Error : Not Registered'](http://stackoverflow.com/questions/26718115/gcm-error-not-registered) – Rocky Mar 29 '16 at 12:57
  • what you want to say.i don't understand.please explain in detail. – Arjun Choudhary Mar 29 '16 at 13:33
  • What do you mean with "Now a days GCM id looks different is google change something in push notification process for eg (fRAvDRuNUU8:APA91bHvSGxi4AVPx2wGTFWb7OyAPPvXoIAcT)" Please improve your writing, because it's not clear what you are asking. – Alessandro Cuttin Mar 31 '16 at 15:43
  • I think push notifications are not sending/receiving after kitkat version.They are not send on lollipop and marshmallow. – Arjun Choudhary Apr 14 '16 at 05:51
  • @Alessandro Cuttin : above code i used in so many apps and it's working fine but in my current app it's not working even on some online site those allow us to send online push notification like : http://apns-gcm.bryantan.info/ also not sending push notification always return below json: { "multicast_id": 5873180458565135923, "success": 0, "failure": 1, "canonical_ids": 0, "results": [ { "error": "NotRegistered" } ] } – Arjun Choudhary Apr 14 '16 at 09:43

1 Answers1

0

Yes my problem is solved now.There were no mistake in my code.it was my mobile developers mistake.Whenever you got response like this way below

` { 
       "multicast_id": 5873180458565135923, 
       "success": 0, 
       "failure": 1, 
       "canonical_ids": 0,
       "results": [ { "error": "NotRegistered" } 

` It is defiantly mistake in android code.

Arjun Choudhary
  • 203
  • 3
  • 16