Android的GCM得到规范ID的原始ID [英] android GCM get original id of canonical id

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

问题描述

我试图发送一个推送更新,一些Android设备。他们中的一些已经得到在此期间一个新的ID,所以谷歌告诉我,有规范的标识。从文档我读:

I am trying to send a push update to some android devices. Some of them have got a new id in the mean time, so I Google tells me there are canonical ids. From the documentation I read:

如果与Message_ID设置,检查registration_id:

If message_id is set, check for registration_id:

  • 如果registration_id设置,替换在服务器数据库中的新值(规范ID)原来的ID。需要注意的是原来的ID不是结果的一部分,所以你需要从registration_ids请求通过了这份名单,这(使用相同的索引)。

我缺少的一部分,或者是这个模糊的,如果你发送超过1登记ID来谷歌?

Am I missing a part, or is this ambiguous if you send more than 1 registration id to Google?

我的要求(取代IDS的可读性):

My request (replaced ids for readability):

"{"data":{"favorite":1},"registration_ids":["1","2","3","4","5","6"]}"

这是谷歌的回应是:

{
  "multicast_id":7917175795873320166,
  "success":6,
  "failure":0,
  "canonical_ids":4,
  "results":[
    {"registration_id":"3","message_id":"m1"},
    {"message_id":"m1"},
    {"message_id":"m1"},
    {"registration_id":"3","message_id":"m1"},
    {"registration_id":"3","message_id":"m1"},
    {"registration_id":"3","message_id":"m1"}
 ]
}

在此,我知道ID 3是正确的,但原来的ID,我应该更换3?发送每封邮件的每个注册ID将是一种浪费。我看过一个帖子在这里#1( GCM和id处理)解决它为Java服务器,但我不是(回报率)。

From this, I know that id 3 is correct, but which original ids should I replace with 3? Sending every message for every registered id would be a waste. I have read a post here on Stackoverflow ( GCM and id handling ) solving it for a Java server, but mine is not (RoR).

在如何解决这个问题的任何想法?

Any ideas on how to solve this issue?

推荐答案

正如在您链接到后描述的,这一切都基于在响应列表中的位置。所以,当你得到规范ID,你需要在同一位置更新原有的注册ID的发送列表。

As described in the post that you linked to, it's all based on the position in the response list. So when you get the canonical ID you need to update the original registration ID in the same position of your "send list".

所以,在你的榜样这里的结果其中4规范(0,3,4,5):

So in your example here are the results 4 of which are canonical (0, 3, 4, 5):

[0] {"registration_id":"3","message_id":"m1"},
[1] {"message_id":"m1"},
[2] {"message_id":"m1"},
[3] {"registration_id":"3","message_id":"m1"},
[4] {"registration_id":"3","message_id":"m1"},
[5] {"registration_id":"3","message_id":"m1"}

这里是你的发送列表:

And here is your "send list":

[0] "1",
[1] "2",
[2] "3",
[3] "4",
[4] "5",
[5] "6"

根据需要更新的注册ID的位置0,3,4,5到3的ID这意味着你将最终获得类似以下的登记表中的结果:

According to the results you need to update the registration ID's in position 0, 3, 4, 5 to the ID of 3. That means that you will end up with a registration list like the following:

[0] "3",
[1] "2",
[2] "3",
[3] "3",
[4] "3",
[5] "3"

最后:

[0] "3",
[1] "2",

另请参见:<一href="https://developer.android.com/google/gcm/adv.html#canonical">https://developer.android.com/google/gcm/adv.html#canonical和<一href="https://developer.android.com/google/gcm/gcm.html#response">https://developer.android.com/google/gcm/gcm.html#response

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

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