0

有没有办法查看设备是否已知对 GCM 服务器空闲?

有没有办法在不使用collapse_key的情况下使用delay_while_idle?

当我在 php 中设置这样的消息时,它确实有效。

$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)
);

当我像这样使用 delay_while_idle 时,它​​不起作用。

$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)
);

我猜这是因为 $messageText 与数据数组中的某些值具有相同的值?当我将其值更改为“你好”时,它确实有效。

4

2 回答 2

1

您可以将 delay_while_idle 设置为 true,而无需指定 collapse_key。

GCM 一次最多支持 4 个折叠键。如果您在设备离线时使用超过 4 个折叠键,则只会保留 4 条消息,并且无法保证会是哪 4 条。

如果您使用消息文本作为折叠键,GCM 将只保存四条唯一消息,您无法知道它最终会传递哪四条消息。

(顺便说一句,如果您确实想使用 collapse_key,我很确定您还必须提供 time_to_live 值,否则请求将被拒绝。)

于 2012-10-31T22:10:56.390 回答
1

我唯一能看到的是您需要用双引号将 $messageText 和所有其他字符串括起来。我还将 delay_while_idle 设置为 1 而不是 true..我知道当你将它传递为 true 时它应该转换为 1。

此外,我认为您没有正确使用 collapse_key(不知道您在那里设置的实际数据无法知道),但通常您会将该字段用作“批处理 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")
);
于 2012-08-28T13:54:38.120 回答