我正在开发一款具有登录功能的应用程序。我只为每个应用程序生成一个 gcm 注册 ID。如果其他用户登录同一个应用程序,他将开始接收针对前一个用户的通知。 如何处理这种情况,以便每个用户都能收到针对他/她的通知? 我应该为每个用户生成 gcm reg id 吗? 处理这种情况的标准方法是什么?
最佳答案
您可以尝试以下操作:
- 当用户注销时,发送请求以删除您服务器上的 token ,并在您的应用程序上将其删除;
- 一旦用户注销,您只需在您的服务器上删除“用户 ID”与“GCM token ”(或注册 ID)的关联。当有人再次登录时,您会与该 token 建立新的关联。
GCM token 是特定于应用程序的,但您在服务器上建立的关联完全取决于您。
我怎么强调都不为过,GCM 生成的 token 是APP SPECIFIC。如果您的用户在多个设备上登录,您的服务器应该处理该问题,将 user ID
关联到多个 Registration ID
token 。
An ID issued by the GCM servers to the Android application that allows it to receive messages. Once the Android application has the registration ID, it sends it to the 3rd-party application server, which uses it to identify each device that has registered to receive messages for a given Android application. In other words, a registration ID is tied to a particular Android application running on a particular device.
根据文档,您的服务器还应该:
Before you can write client apps that use GCM, you must have an application server that meets the following criteria:
- Able to communicate with your client.
- Able to send properly formatted requests to the GCM connection server.
- Able to handle requests and resend them using exponential back-off.
- Able to store the API key and client registration tokens.
- Able to generate message IDs to uniquely identify each message it sends. Message IDs should be unique per sender ID.
编辑:您可以阅读有关 GCM 的更多信息 here .
如需进一步阅读,您还可以在 Device Group Messaging 上阅读更多内容.
您还可以下载一些代码示例 here .
关于android - 我应该生成特定于应用程序还是特定于用户的 android GCM 注册 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32761419/