- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
由于 GCM 不断更新,我搜索过的大部分资源似乎都已过时或不清楚。基本上,我对 token 和 ID 何时到期感到困惑。 (作为引用,我正在使用 Android。)
据我了解(如果我错了,请纠正我),我的服务器有一个 API key 和一个发件人 ID。使用发件人 ID,我可以让我的客户通过本地存储在我的客户端上的 InstanceID 请求 token 。我已经有点困惑了。 InstanceID 是在我的应用上线时分配的?它会改变吗?当应用程序升级或卸载并重新安装(或设备恢复)时怎么办?通过调用 InstanceID.getInstance,我将始终检索相同的 InstanceID,还是它最终会过期并给我一个新的?通过调用 getID() 存储您检索的字符串是否有任何值(value)?文档似乎表明您在调用 getID() 时实际上检索了一个新的 InstanceID,因此这使事情变得更加复杂。 (仅供引用,我指的是:https://developers.google.com/instance-id/)
使用 InstanceID,我的客户端可以从 GCM 服务器请求 token ,然后将其发送到我的应用服务器。我的应用服务器存储了这个 Token,并可以使用它向 GCM 服务器发送消息,然后 GCM 服务器将消息发送到设备。我相信,设备使用存储的 InstanceID 来实际接收这些消息。那么拥有一个扩展 GcmListenerService 的类将允许我使用 onMessageReceived 接收这些消息吗?我不需要做任何特别的事情(除了在 AndroidManifest 中定义它)?我不必实际告诉它使用 InstanceID?它只是神奇地知道?
这些 ID 和 token 什么时候到期?它们会过期吗?我将 token 作为字符串存储在服务器上,但如果其中任何一个过期,我怎么知道它们已经过期?我总是可以生成一个新的 InstanceID 和 Token,这看起来很容易,但是旧的是否保持 Activity 状态?如何从服务器上删除旧 token ?似乎有一种简单的方法可以在 iOS 端使用 APNS 执行此操作,您可以在其中检索所有过期 token 的列表,然后将它们从数据库中删除。
最佳答案
当我更新我的 GCM 实现时,我发现自己问了大部分这些问题。在搞砸了几天之后,这是我对您的问题的看法。
From what I understand (and please correct me if I'm wrong), my server has an API Key and a Sender ID. Using the Sender ID I can have my client request a Token via the InstanceID stored locally on my client.
这是正确的。
The InstanceID is assigned the moment my app goes online?
它似乎是在您的应用启动后立即分配的,即使设备无法访问互联网。
Does it ever change? What about when the app upgrades or is uninstalled and reinstalled (or the device is restored)? By calling InstanceID.getInstance will I always retrieve the same InstanceID, or will it eventually expire and give me a new one?
Instance ID is stable but may become invalid, if:
- App deletes Instance ID
- Device is factory reset
- User uninstalls the app
- User clears app data
If Instance ID has become invalid, the app can call getId() to request a new Instance ID.
我已经测试了卸载应用并清除数据,结果表明以上所有内容都是正确的。
Is there any value to storing the string you retrieve by calling getID()?
看起来 API 会为您将其存储在应用的本地存储中。
Using the InstanceID, my client can request a Token from the GCM servers, which it then sends to my app server. My app server stores this Token, and can use this to send messages to the GCM servers, which will then send the message to the device. The device uses the stored InstanceID to actually receive these messages, I believe. So having a class that extends GcmListenerService will allow me to receive these messages with onMessageReceived? I don't have to do anything special (other than defining it in the AndroidManifest)? I don't have to actually tell it to use the InstanceID? It just magically knows?
据我所知,在之前的实现中没有任何类型的 InstanceId,而且它看起来也没有在这个实现中明确使用。如果是,它会在 GcmReceiver 中被调用。或 GcmListenerService .
When do these ID's and Tokens expire? Do they expire?
我已经解决了 ID 的过期问题,我们可以在 Android InstanceID implementation guide 中找到有关 token 过期的信息。 :
The Instance ID service initiates callbacks periodically (for example, every 6 months), requesting that your app refreshes its tokens. It may also initiate callbacks when:
- There are security issues; for example, SSL or platform issues.
- Device information is no longer valid; for example, backup and restore.
- The Instance ID service is otherwise affected.
指南说子类InstanceIDListenerService并覆盖 onTokenRefresh()
来处理这些场景。
I store the Token as a string on the server, but if at any point one of these expires, how do I know they have expired?
guide for implementing GCM on your server表示 GCM 服务器将向您的服务器响应一些有关您用于尝试发送推送通知的 token 的信息。
I can always generate a new InstanceID and Token, that much seems easy, but then do the old ones stay active?
我的测试表明是的,确实如此。
How do I wipe the old tokens from the server? There seems to be an easy way to do this with APNS on the iOS side of things, where you can retrieve a list of all the expired tokens and just wipe them from your database.
我仍在研究这个问题,如果我能解决问题,我会更新。
关于android - GCM token 什么时候到期,InstanceID 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31061354/
我想我理解 GCM 的新 notification_key 功能背后的基本原理是“只需将消息发送给用户并且只让他们阅读一次”。我从文档的这一部分推断出来: With user notification
我实现了网络推送通知。获取错误的步骤: 打开网站 订阅推送通知 通过 gcm 发送许多推送 - 一切正常 关闭网站标签 发送推送和接收“双推送”- 第一个正常,第二个是“此站点已在后台更新” 重新打开
我正在手机上测试 GCM。 (2.3.6 安卓). list 文件(MainActivity、First 和 Second Activity 不执行任何操作,它们用于其他一些测试目的,不干扰 GCM)
首先,我是 iOS 开发的新手,也是 swift 的新手。我正在尝试让适用于 iOS 的谷歌云消息传递示例。 我已经从 https://developers.google.com/cloud-mess
你们中的任何人都可以提供 GCM 推送通知的代码,其中消息从移动设备推送到 GCM 服务器。我已经从 GCM 服务器到移动设备及其工作进行了操作,但我不知道反之亦然如何操作。任何人都可以提供帮助吗?谢
我们有两个不同的应用程序,但都需要来自 Google Cloud Messages 的相同推送通知,并且我在两个应用程序中只使用了一个发件人 ID(启用 Google 控制台之一的项目编号)。 这样做
我有一个广播接收器,当应用程序打开并在后台时,它会检测即将到来的通知,但当最近的应用程序被清除时,接收器无法工作,请给我建议。 public class GcmBroadcastReceiver ex
我想从我的应用程序向 GCM 服务器发送一个心跳信号,以便连接保持有效。 我该怎么做,我怎么知道我的 GCM 服务器的 URL? 提前致谢! 最佳答案 如何发送心跳 这个类可以发送正确的 Intent
新的 GCM 3.0 应该允许 GCM 自动显示从服务器发送的通知,如果它们包含 notification 参数。 如 docs 中所述: The notification parameter wit
这个问题在这里已经有了答案: Do I need to migrate GCM to FCM on client side? (2 个答案) 关闭 3 年前。 Google 已于 2018 年 4
我遇到了 GCM 推送通知无法正确到达 Android 设备的问题。经过几天的研究,我发现 Android 设备使用心跳来保持与 GCM 服务的连接。遗憾的是,心跳似乎太高了,因此 Android 设
阅读堆栈溢出 2 天后我做了什么: 问题关键字:“Apple-Mach-O 链接器错误”、“libGcmLib.a(GCMRmqManager.o) ", sqlite3", "GCMRmq2Pers
我已经从 GCM 订阅了主题,当我通过 Android 设置删除所有应用程序数据时,GCM token 是相同的,关于主题的 GCM 通知仍然可用,所以我收到了我不想收到的通知。 我的问题是: 如何从
由于 gcm 已弃用,我们希望迁移我们的代码。正如在谷歌的迁移指南中提到的那样,对于我们的服务器应用程序,应该只需要将端点从 gcm 更改为 fcm。应用迁移已成功完成。 我们现在使用的是 com.g
这只发生在我的 Kyocera Rise 上。我有一个依赖 GCM 在手机之间进行通信的应用程序。我的 Nexus 4 和我的 HTC One X 之间的通信工作正常,每当我发送推送通知时,两部手机都
我遇到了与 this 相同的问题.我会尝试提供更多信息。 我正在使用 Play Framework,用 Java 编写。我写了一个叫做 PushNotificationQueue 的插件。 PushN
我需要在我的应用程序中接收来自不同发件人的推送通知。会成功吗? 最佳答案 你的问题的答案是是! 根据 GCM 的官方文档,您的应用可以接收来自多个发件人的消息(限制为 100 个不同的发件人),并且您
我有一个使用 GCM 推送通知的应用程序。它工作正常,我的设备注册并接收推送消息。 如果我从我的设备上卸载该应用程序,我将不再像您期望的那样收到消息。在我卸载应用程序后,您在服务器上发送消息的文本框仍
我正在处理另一个开发人员的现有项目,我需要获取 PubNub 设置的 GCM 服务器 key ,因为它被意外删除了。 有什么方法可以从 Google 设置中检索它?我在凭据和项目设置中找不到它。 我暂
嘿,我在调用 `subscribeToTopicP 类时遇到了一些 Gcm Intent 服务的问题,总是出现空指针异常。 这是我的代码: GcmIntentService.java private
我是一名优秀的程序员,十分优秀!