I'm currently working on GCM for android and implement the server code using PHP. Right now, my code looks like this:
$url = 'https://android.googleapis.com/gcm/send';
$registrationIDs = array('device1', 'device2');//device ids from database.
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array( "message" => $message ),
);
$headers = array(
'Authorization: key=' . $apiKey,
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Execute post
$result = curl_exec($ch);
// Close connection
curl_close($ch);
When I execute, the result are as follows:
{
"multicast_id": 5407120473654582795,
"success": 1,
"failure": 1,
"canonical_ids": 1,
"results": [
{
"registration_id": "skjdfhksdfgksudghldshfgkdjfghdiugf",
"message_id": "0:1354101888763222%14c0e050f9fd7ecd"
},
{
"error": "MismatchSenderId"
}
]
}
There are notes on GCM page:
- If the message was created but the result returned a canonical registration ID, it's necessary to replace the current registration ID with the canonical one.
- If the returned error is NotRegistered, it's necessary to remove that registration ID, because the application was uninstalled from the device.
My question are:
- Based on the server output, I have 1 canonical result. But, I'm not sure it belong to which device. How do I determine it?
- Based on question (1), I get the idea that I might be able to send device to GCM one at a time. But, this raise another question. What if I have millions of device, will that be OK?