Android的GCM得到规范ID的原始ID原始、Android、GCM、ID

由网友(孤身浪子)分享简介:我试图发送一个推送更新,一些Android设备。他们中的一些已经得到在此期间一个新的ID,所以谷歌告诉我,有规范的标识。从文档我读:I am trying to send a push update to some android devices. Some of them have got a new id in...

我试图发送一个推送更新,一些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",

另请参见:https://developer.android.com/google/gcm/adv.html#canonical和https://developer.android.com/google/gcm/gcm.html#response

阅读全文

相关推荐

最新文章