Sending push-notification to android app developed in titanium (cross-platform) using PHP -


to send push-notification server android app using following script.

<?php     $message = "hi there";     $apikey = "xxxxxxxxxxxx";      $registrationids = array("xxxxxxx");     $url = 'https://android.googleapis.com/gcm/send';        // set post variables     $fields = array(         'registration_ids' => $registrationids,         'data' => array( "message"  => $message,                          )                         );     $headers = array(         'authorization: key=' . $apikey,         'content-type: application/json'     );     $ch = curl_init(); // open connection     curl_setopt($ch, curlopt_url, $url );     // set url, number of post vars, post data     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);   // execute post       if($result === false)         die('curl failed ' . curl_error());      curl_close($ch);     //return $result;     // curl_close($ch);          // close connection     $response = json_decode($result);     print_r($response); ?> 

this code works fine native android app, app developed in titanium when send push-notification above script, device receives notification "null" payload.

i want know, why? wrong php script.

update

this code receive notification

// these events monitor incoming push notifications  cloudpush.addeventlistener('callback', function (evt) {      //ti.api.info('this payload data got'+json.parse(evt.payload));      ti.api.log("this gcm response "+json.stringify(evt));       alert(evt.payload);      //var payload = json.parse(evt.payload);      //ti.api.info('this message data got'+payload.message);   });  cloudpush.addeventlistener('trayclicklaunchedapp', function (evt) {      ti.api.info('tray click launched app (app not running)');  });  cloudpush.addeventlistener('trayclickfocusedapp', function (evt) {      ti.api.info('tray click focused app (app running)');  }); 

and response

[info] :   apscloudpush: receivepayload: null [info] :   apscloudpush: background: true [info] :   apscloudpush: queuepayload: null [info] :   apscloudpush: showtraynotification [error] :  apscloudpush: payload null! 

the code above given absolutely correct. guess problem keyword payload. replace word "message" "payload" @ server side script below.

    $fields = array(     'registration_ids' => $registrationids,     'data' => array( "payload"  => $message,                      )      ); 

because in titanium ti.cloudepush module internally search word payload


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -