I am using PHP to send Notifications on multiple android devices at a time. All registration ids are unique, following is the CURL request that I am sending.
$url='https://android.googleapis.com/gcm/send'; $headers = array( 'Authorization: key=' . ANDROID_KEY, 'Content-Type: application/json' ); $registration_ids = [];//with multiple registration ids $notification = array( 'registration_ids' => $registration_ids, 'data' => array('notification_id' => $data['notification_id'], 'title' => $data['title'], 'message' => $data['message']) ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($notification)); $res = curl_exec($ch);
After debugging multiple times I could not find any reason for multiple notifications(more than 10 times) on the same device.
Is there any way to check the log of requests received by GCM. Any lead will be appreciated.
Google Cloud Messaging (GCM) was a mobile notification service developed by Google that enables third-party application developers to send notification data or information from developer-run servers to applications that target the Google Android Operating System, as well as applications or extensions developed for the ...
FCM is a cloud platform that provides messages and push notifications for operating systems- ios and Android, and websites as well. Google Cloud Messaging is a messaging service that enables the message transfer from server to clients apps.
This document describes the Google Cloud Messaging (GCM) HTTP connection server. Connection servers are the Google-provided servers that take messages from the 3rd-party application server and sending them to the device.
I figured the problem was with my android implementation. The device was getting registered multiple times.
GCM returns the same registration id for a device till the next reinstall. In some cases when the registration id gets expired/invalid GCM returns a new one.
At the time of pushing GCM will return the canonical registration id for expired/invalid token.
The solution is to read the response and update old registration id with the new one in the db.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With