android GCM获取规范ID的原始ID [英] android GCM get original id of canonical id

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

问题描述

我正在尝试向某些 Android 设备发送推送更新.他们中的一些人同时获得了一个新的 id,所以我谷歌告诉我有规范的 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列表中获取(使用同一个索引).

我是否遗漏了一部分,或者如果您向 Google 发送了 1 个以上的注册 ID,这是否有歧义?

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

我的请求(为了可读性替换了 id):

My request (replaced ids for readability):

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

Google 的回复是:

The response from Google is:

{
  "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 发送每条消息将是一种浪费.我在 Stackoverflow 上读过一篇文章(GCM 和 id 处理)为 Java 服务器解决了这个问题,但我的不是(RoR).

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

这是您的发送列表":

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

根据结果,您需要将位置 0、3、4、5 的注册 ID 更新为 ID 3.这意味着您最终会得到如下所示的注册列表:

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#规范https://developer.android.com/google/gcm/gcm.html#回复

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

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