用户通知 - 如何恢复丢失notification_id从GCM? [英] User Notifications - How to recover a lost notification_id from GCM?

查看:376
本文介绍了用户通知 - 如何恢复丢失notification_id从GCM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我生成 notification_key 取值所描述的>。

I generate notification_keys as described here.

假设由于一些错误我不能存储,所以我尝试重新注册。
这一次,我收到一个400错误的信息notification_key已存在
这看起来很奇怪,尤其是相对于设备的
登记到GCM 的,只要你想,你可以注册多次,一定可以得到与状态200
相同的注册ID 现在,我不能再注册,我也不能注销,因为我没有 notification_id

有没有什么办法让pviously产生 notification_key 从GCM的$ P $?
或者是与重新注册的唯一方法不同的 notification_key_name

Suppose that due to some error I fail to store it, so I try to re-register.
This time I receive a 400 error with the message "notification_key already exists".
This looks odd, especially compared to registration of a device to GCM, where you can register as many times as you want and always get the same Registration ID with status 200.
Now I can't register again, and I also can't unregister, because I don't have the notification_id.

Is there any way to get the previously generated notification_key from GCM?
Or is the only way to register again with a different notification_key_name?

推荐答案

根据该文档,没有办法从GCM的 notification_key 现有的<$得到C $ C> notification_key_name 。如果你想想看,这是有道理的,试图创建一个新的 notification_key 在现有的 notification_key_name 会给你一个错误,因为如果不是这样,你可能会意外地覆盖现有的 notification_key 如果你碰巧提供现有 notification_key_name的注册标识错误。

Based on the docs, there is no way to get from GCM the notification_key of an existing notification_key_name. If you think about it, it makes sense that trying to create a new notification_key for an existing notification_key_name would give you an error, since if it wasn't the case, you might be accidentally overwriting the Registration IDs of an existing notification_key if you happen to supply an existing notification_key_name by mistake.

正在比较这对登记设备GCM多次,每次都得到相同的注册ID,但它不是一个类似的情况。当您注册一个设备到GCM,GCM有办法识别设备,并知道它是已注册并返回相同的注册ID。随着用户的通知,它不仅具有 notification_key_name 你提供的,并没有什么使用相同的阻止你 notification_key_name 的多个用户。也就是说,有一些东西阻止你 - 试图创建一个 notification_key 以previously使用 notification_key_name

You are comparing this to registering a device to GCM multiple times, each time getting the same Registration ID, but it's not a similar situation. When you register a device to GCM, GCM has a way to identify the device and know that it is already registered and return the same Registration ID. With user notifications, it only has the notification_key_name that you supplied, and there's nothing stopping you from using the same notification_key_name for multiple users. That is, there is something stopping you - the error you got when trying to create a notification_key with a previously used notification_key_name.

这是简单的方法来解决你的问题是治疗 notification_key_name 由服务器生成的唯一标识符。如果你没有一个 notification_key 某个用户(可能是因为它是一个新的用户或者是因为你没有存储 notification_key 您$ P $从谷歌pviously了),你生成一个新的独特的 notification_key_name ,并用它来创建一个新的 notification_key 。你不必关心老 notification_key ,你没有商店。

An easy way to overcome your problem is to treat notification_key_name as a unique identifier generated by your server. If you don't have a notification_key for a certain user (either because it's a new user or because you failed to store the notification_key you previously got from Google), you generate a new unique notification_key_name and use it to create a new notification_key. You don't have to care about the old notification_key that you failed to store.

最后,你同时存储 notification_key notification_key_name 中包含用户ID,表

Finally you store both the notification_key and notification_key_name in a table that contains the user id.

这篇关于用户通知 - 如何恢复丢失notification_id从GCM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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