GCM 规范 ID [英] GCM canonical id

查看:21
本文介绍了GCM 规范 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当 1 个设备有多个 regid 时,GCM 返回规范 ID 错误:

When having multiple regids for 1 device GCM returns the canonical id error:

{"multicast_id":xxxx,"success":2,"failure":0,"canonical_ids":1,"results":[{"message_id":"xxxxx"},{"registration_id":"newest reg ID here","message_id":"xxxxxx"}]}

所以它显示了 GCM 应该使用的最新 regid,但为什么它不显示您应该删除的 regid(旧的)?我如何知道旧的 regid 是什么以及我应该从我的数据库中删除哪个?

So it shows the newest regid that should be used by GCM but why isn't it showing the regid that you should delete (the old one)? How do I know what the old regid is and which one I should delete from my database?

推荐答案

Eran 的回答是正确的,尽管我发现它对我来说仍然有点模糊.不过,多亏了他,我找到了解决办法.

Eran's answer is correct, though I found it still a bit foggy for me. However, thanks to him I found a solution.

说这是你的回应:

{
   "multicast_id":xxxxx,
   "success":7,
   "failure":0,
   "canonical_ids":2,
   "results":[
      {
         "message_id":"0:xxx%xxxxx"
      },
      {
         "message_id":"0:xxx%xxxxx"
      },
      {
         "registration_id":"MY_REG_ID_1",
         "message_id":"0:xxx%xxxxx"
      },
      {
         "message_id":"0:xxx%xxxxx"
      },
      {
         "message_id":"0:xxx%xxxxx"
      },
      {
         "registration_id":"MY_REG_ID_2",
         "message_id":"0:xxx%xxxxx"
      },
      {
         "message_id":"0:xxx%xxxxx"
      }
   ]
}

如您所见,7 条消息中有 2 条是重复的.

As you can see 2 of the 7 messages are a duplicate.

这是我向服务器发送消息的方式:

This is the way I send messages to the server:

$tokenResult = mysql_query("SELECT reg_ids FROM table_with_regids"); //
$i = 0;
while($row = mysql_fetch_array($tokenResult)) {

     $registrationIDs[$i] = $row['reg_ids'];
     $i++;
}

来自 Eran 的回答:

由于您收到 Google 对您发送的每个请求的回复,您应该知道请求中向 Google 发送了哪些注册 ID触发了这个反应.您必须使用的旧注册 IDdelete 是该请求中的第二个注册 ID.

Since you get a response from Google for each request you send, you should know which Registration IDs were sent to Google in the request that triggered this response. The old Registration ID that you have to delete is the second Registration ID in that request.

这意味着数组$registrationIDs[]的索引25应替换为MY_REG_ID_1MY_REG_ID_2.

This means that index 2 and 5 of the array $registrationIDs[] should be replaced with MY_REG_ID_1 and MY_REG_ID_2.

最后检查双精度值并删除完全重复的值.结果应该是一个包含 5 个 regid 的数组(或直接从数组中删除该索引而不是替换为 MY_REG_ID_#).

Finally check for double values and remove the exact duplicates. The result should be an array with 5 regids (or directly delete that index from your array instead of replacing with MY_REG_ID_#).

这篇关于GCM 规范 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆