Reputation: 5644
Is there a way to see if a device is known to be idle to the GCM server?
Is there a way to use delay_while_idle without using a collapse_key?
When I setup my message like this in php it does work.
$headers = array("Content-Type:" . "application/json", "Authorization:" . "key=" . $key);
$data = array(
'registration_ids' => $deviceRegistrationIds,
'data' => array('message' => $messageText,
'msgfromname' => $fromname,
'close' => $close,
'newchat' => $newchat,
'msgfrom' => $from)
);
When I use delay_while_idle like this it does not work.
$headers = array("Content-Type:" . "application/json", "Authorization:" . "key=" . $key);
$data = array(
'registration_ids' => $deviceRegistrationIds,
'collapse_key' => $messageText,
'delay_while_idle' => true,
'data' => array('message' => $messageText,
'msgfromname' => $fromname,
'close' => $close,
'newchat' => $newchat,
'msgfrom' => $from)
);
I guess this is because $messageText has a same value as something in the data array? When I change it's value to 'hello' it does work.
Upvotes: 0
Views: 3621
Reputation: 6311
You can set delay_while_idle to true without specifying a collapse_key.
GCM only supports up to 4 collapse keys at a time. If you use more than 4 collapse keys while a device is offline, only 4 of the messages will be kept, and there is no guarantee which 4 it will be.
If you use the message text as the collapse key, GCM will only hold four unique messages, and there's no way for you to know which four messages it will end up delivering.
(BTW, if you do want to use a collapse_key, I'm pretty sure you must also provide a time_to_live value or the request will be rejected.)
Upvotes: 1
Reputation: 794
Only thing I can see is you need to surround $messageText and all other string with double quotes. I've also set delay_while_idle to 1 instead of true..I know it should convert to 1 when you pass it true.
Also I dont think you're using the collapse_key correctly (Cant know without knowing what actual data you're setting there) but typically you'll use that field as a "batch id".
$headers = array("Content-Type:" . "application/json", "Authorization:" . "key=" . $key);
$data = array(
'registration_ids' => $deviceRegistrationIds,
'collapse_key' => "$messageText",
'delay_while_idle' => 1,
'data' => array('message' => "$messageText",
'msgfromname' => "$fromname",
'close' => "$close",
'newchat' => "$newchat",
'msgfrom' => "$from")
);
Upvotes: 1