GCM:发送通知仅适用于当前用户登录应用 [英] GCM: Send notifications only for the current user logged in application

查看:159
本文介绍了GCM:发送通知仅适用于当前用户登录应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关,我的工作,我需要整合谷歌云消息传递应用程序。扮演的是一个不同的例子后,我就能够发送和接收我的deivce通知。
然而,我所遇到的一个有趣的情况。据我所知(请纠正我,如果我错了),在registration_id是每台设备,每个应用程序发出的。

For the application that I am working I need to integrate Google Cloud Messaging. After playing a little with different examples, I was able to send and receive a notification on my deivce.
However, I have come across an interesting situation. As I know (please correct me if I'm wrong), the registration_id is issued per device and per application.

这是我的工作支持登录功能的应用。当应用程序安装,用户登录的第一次(让它是用户A),我请求GCM,然后我将它发送到我的服务器的registration_id。

The application that I'm working supports login functionality. When the application is installed and the user logs in for the first time (let it be "UserA"), I request the registration_id from GCM which then I send it to my server.

现在想象一下用户a注销,并给他的装置,一些用户B在用户A使用的设备登录。随着换言之,用户B日志。

Now imagine that UserA logs out and gives his device to some UserB to log in. With other words, UserB logs in using UserA's device.

的问题是,如果用户a同时收到通知时,用户B将能够拦截。如果用户B收到通知,他将不能够接受它。
这似乎是正常的,因为registration_id是每台设备,每个应用程序,但它似乎没有合理的我的情况。

The problem is that if meanwhile UserA receives a notification, UserB will be able to intercept it. And if UserB receives a notification, he won't be able to receive it.
This seems normal because the registration_id is per device and per application, but it does not seem reasonable for my case.

于是我问,如果有一种方法,我可以使registration_id要依赖一些用户ID(除了设备和应用程序)?或者,我怎么能做出这样的登录用户只接收自己的通知?

So I'm asking if there is a way I could make the registration_id to be dependent of some user id (besides the device and app)? Or how could I make such that the logged in user to receive only his own notifications?

推荐答案

是它的真实,你对每个器件的应用1谷歌的注册ID。

Yes its true that you have one google registration ID for the app per device.

但你总是可以注册和注销的用户在自己的服务器,将实际发送消息给GCM和GCM将发送这对注册设备。

But you can always register and unregister users at your own Server that will actually send messages to GCM and GCM will send this to the registered devices.

定义一些接口,为您的服务器像registerOnServer和unRegisteronServer,发送一些独特的价值为这个接口上的每个用户。

Define some interfaces for your Server like registerOnServer and unRegisteronServer , send some unique value for each user on this interface.

那么,在你的情况下,当使用日志插件,regitration是在GCM完成第一和注册用户提供registerOnServer inteface您的服务器上,并在用户登录送有关他GCM将通知发送到设备。

So, in your case, when A use Log ins , regitration is done on GCM first and register the user on your Server with registerOnServer inteface and while the user is logged in send notifications pertaining to him to GCM to be send to the device.

在注销,注销他用unRegisterServer并没有从服务器到GCM发送任何消息,因为A是未注册的。

When A logs out, unregister him using unRegisterServer and do not send any messages from your Server to GCM as A is unregistered.

所以,现在如果B退出,即使使用相同的设备,他注册在你的服务器,并派他的消息。

So,now if B Logs in even with the same device , register him at your Server and send his messages.

本应解决您的问题!

这篇关于GCM:发送通知仅适用于当前用户登录应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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