I have created a mobile application with Push Notification. The App grabs the Token from Google FCM stores it into a database. Then we use a dashboard to send a notification to all registered devices.
There has been an issue with our notifications. Although it shows successful on FCM Response, the message does not go to devices.
FCM Response: {"multicast_id":8418406699445470273,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1531307530435857%b446114df9fd7ecd"}]}
PHP Code:
$url = 'https://fcm.googleapis.com/fcm/send';
// Set GCM post variables (device IDs and push payload)
$post = array(
'registration_ids' => $ids,
'data' => $data,
'priority' => 'high',
'notification' => $data,
);
// Set CURL request headers (authentication and type)
$headers = array(
'Authorization: key=' . $apiKey,
'Content-Type: application/json'
);
// Initialize curl handle
$ch = curl_init();
// Set URL to GCM endpoint
curl_setopt( $ch, CURLOPT_URL, $url );
// Set request method to POST
curl_setopt( $ch, CURLOPT_POST, true );
// Set our custom headers
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
// Get the response back as string instead of printing it
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
// Set JSON post data
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $post ) );
// Actually send the push
$result = curl_exec( $ch );
// Error handling
if ( curl_errno( $ch ) )
{
echo 'GCM error: ' . curl_error( $ch );
}
// Close curl handle
curl_close( $ch );
// Debug GCM response
echo $result;
I have sent the same message through Google Cloud Message Console and it did send the notification to my device.
Has anyone had this problem before?
Thank you in advance.