GCM规范ID [英] GCM canonical id

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

问题描述

1的设备具有多个regids当GCM返回规范ID错误:

<$p$p><$c$c>{"multicast_id":xxxx,"success":2,"failure":0,"canonical_ids":1,"results":[{"message_id":"xxxxx"},{"registration_id":"newest章编号这里,与Message_ID:XXXXXX}]}

因此​​,它显示了应使用GCM,但为什么不显示你应该删除REGID(旧)最新的REGID?我怎么知道老REGID是什么,哪一个我应该从我的数据库中删除?

解决方案

伊兰的答案是正确的,但我觉得还是有点云里雾里我。然而,由于他,我找到了一个解决方案。

这样说,是你的回应:

  {
   multicast_id:XXXXX,
   成功:7,
   失败:0,
   canonical_ids:2,
   结果:
      {
         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
      }
   ]
}
 

正如你可以看到2 7的消息是重复的。

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

  $ tokenResult =请求mysql_query(选择reg_ids从table_with_regids); //
$ i = 0;
而($行= mysql_fetch_array($ tokenResult)){

     $ registrationIDs [$ i] = $行['reg_ids'];
     $ I ++;
}
 

从叶兰的回答:

  

既然你从谷歌回应给你送,你的每个请求   要知道注册的ID被发送到谷歌的请求   引发这种反应。你有旧的注册ID   删除是在请求中的第二个注册ID。

这意味着,指数 2 5 的数组的 $ registrationIDs [] 应替换为 MY_REG_ID_1 MY_REG_ID_2

最后,检查双重价值,并删除了确切的重复。其结果应符合5 regids一个数组(或者直接删除与MY_REG_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"}]}

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's answer is correct, though I found it still a bit foggy for me. However, thanks to him I found a solution.

Say this is your response:

{
   "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"
      }
   ]
}

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++;
}

from Eran's answer:

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.

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

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天全站免登陆