Gcm With PHP (Google Cloud Messaging)

Warning on GCM with PHP

the data which you are passing should be an array not a string like this

  $messageData =  array(
'success' => 1,
'title' => $data['title'],
'desc' => $data['message']
);

Google Cloud Messaging- Sending Push Message To Android Using PHP

Maybe this will work:

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

GCM message does not reach destination in PHP

It seems there is some issue with your testGCM() function. Can you log the $pushStatus variable to see what is there or is it null. Also there is no code where you are parsing the JSON array returned after the request. You can check the error logs in logcat to investigate the issue.

Here are some tutorials that would help you find more about the implementation issues:

http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/

https://github.com/mattg888/GCM-PHP-Server-Push-Message

http://www.androidbegin.com/tutorial/android-google-cloud-messaging-gcm-tutorial/

Hope this helps!!!

Google Cloud Messaging returns Invalid Registration

mysqli_query returns Boolen value (true or false) so this will not going to works directly.

we have to convert mysqli_query return values to array using fetch array, fetch assoc.

$results = mysqli_query($Thesisdb, $sql);

$registrationIds = array($results);

Code to combile all GCM Tokens.

registrationIds=array();
$sql="SELECT `user_id`,`push_notification_registration_id` FROM `tbl1` WHERE `user_status`='Active' AND `push_notification_registration_id`!=''";
$fire=mysqli_query($this->conn,$sql);
$users=array();
if( (isset($fire))&&(!empty($fire)) ){
while($result=mysqli_fetch_assoc($fire)){
array_push($users,$result);
}
}
foreach($users as $single_user){
$register_id=$single_user['push_notification_registration_id'];
array_push($registrationIds,$register_id);
}


$msg = array
(
'title' => $news_title,
'subtitle' => $news_description,
'tickerText' => 'Ticker Text',
'vibrate' => 1,
'sound' => 1,
'news_id' => $news_id,
'notification_type' => 'news'
);

$fields = array
(
'registration_ids' => $registrationIds,
'data' => $msg
);

$headers = array
(
'Authorization: key=' . YOUR_GOOGLE_API_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,true ) );
$result = curl_exec($ch );
curl_close( $ch );

GCM Only Sends Message to Latest Registered Device in php

Check if the new deviceId being stored is not clearing the original contents. I.e. the file operation while adding a new device id Should be of append mode. This might be causing the problem of sending only to the latest device.



Related Topics



Leave a reply



Submit