简体   繁体   English

pubnub如何处理推送通知

[英]How pubnub handle push notification

I am creating android chat app using PubNub.I am using GCM push gateway with pubnub to publish messages to channel. 我正在使用PubNub创建android聊天应用程序。我正在使用带有pubnub的GCM推送网关向消息发布消息。 Let's say User A and User B start a private chat. 假设用户A和用户B开始私聊。

case 1 - A and B is connected to internet 案例1 - A和B连接到互联网

App is working perfectly. 应用程序运行正常。 If "A" sends a message to B, "B" receive it regardless the app is in foreground or background. 如果“A”向B发送消息,“B”接收它,无论应用程序是在前台还是后台。

case 2 - A or B is not connected to internet 案例2 - A或B未连接到互联网

Lets say "A" is connected to internet and "B" is not. 让我们说“A”连接到互联网而“B”则不连接。 "A" publish a message to "B". “A”向“B”发布消息。

Can I know, what will happen in Pubnub-end and GCM-end in this case-2? 我可以知道,在这种情况下,Pubnub-end和GCM-end会发生什么?

This is the way I am publishing the message. 这是我发布消息的方式。

        PnGcmMessage gcmMessage = new PnGcmMessage();
        try {
            gcmMessage.put("delay_while_idle", true);
        }catch (Exception e){
           e.printStackTrace();
        }
        gcmMessage.setData(messageObject);

        PnMessage message = new PnMessage(
                pubnub,
                channel,
                callback,
                gcmMessage);
        try {
            message.put("pn_debug", true);
            message.publish();
        } catch (PubnubException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }

I am still getting familiar with creating real time messaging applications. 我仍然熟悉创建实时消息传递应用程序。 So I don't know what is missing there. 所以我不知道那里缺少什么。 So please guide me on handling this issue. 所以请指导我处理这个问题。

PubNub Mobile Push Gateway PubNub移动推送网关

The PubNub Mobile Push Gateway allows you to use GCM (Android), APNS (iOS) & MPNS (Windows Phone) as a fallback mechanism for your mobile apps to receive messages when your app is not actively running and connected to PubNub. PubNub移动推送网关允许您使用GCM(Android),APNS(iOS)和MPNS(Windows Phone)作为移动应用程序的后备机制,以便在您的应用未主动运行并连接到PubNub时接收消息。

This PubNub article, Sending APNS and GCM Messages to Subscribers and Mobile Push Notifications Services in One API Call , serves as a mini-FAQ for PubNub mobile push notifications. 这篇PubNub文章, 在一个API调用中向订阅者和移动推送通知服务发送APNS和GCM消息 ,作为PubNub移动推送通知的迷你常见问题解答。 There is a short video at the end that serves as a summary of this article. 最后有一个简短的视频作为本文的摘要。

Sending PubNub Realtime Messages & GCM Push Notifications 发送PubNub实时消息和GCM推送通知

If the app that is publishing is not connected to the internet (via cell or wifi), then the publish will fail. 如果正在发布的应用程序未连接到Internet(通过单元格或wifi),则发布将失败。 Your app (not just the device) must be running/active/connected (in foreground or background) to the internet in order to be connected to PubNub and publish messages. 您的应用程序 (不仅仅是设备)必须正在运行/活动/连接(在前台或后台)到Internet才能连接到PubNub并发布消息。

Receiving PubNub Realtime Messages vs GCM Push Notifications 接收PubNub实时消息与GCM推送通知

If the subscriber app is not connected to the internet, then your app will not receive the published message via the subscribe callback (the PubNub realtime message). 如果订阅者应用程序未连接到互联网,则您的应用程序将不会通过subscribe回调(PubNub实时消息)接收已发布的消息。

If the device has some sort of connectivity (cell or wifi) so that the GCM service (this is not PubNub) can send push notifications to the device, then the GCM message that was included in the published message will reach your app. 如果设备具有某种连接(单元或wifi),以便GCM服务(这不是PubNub)可以向设备发送推送通知,则已发布消息中包含的GCM消息将到达您的应用程序。

See also: 也可以看看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM