Pubnub推送通知不适用于跨平台移动应用程序 [英] Pubnub Push Notification not working for cross platform mobile app

查看:645
本文介绍了Pubnub推送通知不适用于跨平台移动应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发一个基于cordova的Android应用程序,具有聊天功能。
我们从服务器发送测试聊天消息,当应用处于前台时,我们收到的消息很好。



我们希望获得有关聊天消息,当应用程序在后台。
但是我们没有收到关于聊天消息的推送通知。



我们所遵循的步骤如下。请告诉我们我们所犯的错误。



我们已经提到

我们使用cordova PushPlugin注册,以便在设备上获得通知。

推送通知设备。并使用以下代码注册设备

  pubnub.mobile_gw_provision({
device_id:'A655FBA9931AB',
:'add',
gw_type:'gcm',// or'apns'
channel:'my_chat',
callback:mySuccessCallback,
error:myErrorCallback,
});

如果我们以编程方式发送使用GCM设备ID从我们的服务器发送推送通知,使用GCM API。



当应用程序处于前台时,我们从pubnub的onNotificationGCM方法接收通知警报。



我们还在管理控制台中配置了GCM服务器API密钥,并启用了pubnub推送通知。



我使用下面的Python代码发布聊天:

  _pubnub = Pubnub(publish_key ='our-publish-key',
subscribe_key ='our-sub-key')

channel_name ='here-is-channel-string'
data = dict(
pn_gcm = dict(data = dict(
title_for_mobile ='PN',
summary_for_mobile = ['Hi,test']

) ,
text ='你的dob是什么?',
sender = dict(name ='Jon Snow',id ='yyyyyyyy'),
meta = dict ='zzzzzzzz'))


_pubnub.publish(channel_name,data)


b $ b

当应用程序为
时,在后台获取传入聊天消息的推送通知是我的应用程序的关键功能。



请让我知道我做错了?

解决方案

我也在Pubnub的支持下提出了一个支持请求。在Pubnub的一些好听的回复之后,我们能够解决它。



我们误导了此文档,我们正在使用

 pn_gcm:{
data:{
title_for_mobile:Test,
summary_for_mobile:[Hi]
}
}

而是应该使用。

  {
message:这是一些文本,
pn_gcm:{
data:{
title:Demo wpush,
message:这是一个pushnotification
}
},
pn_debug:true
}

因为Cordova PushPlugin期待 message GCM

  // GCMIntentService.java 
@Override
protected void onMessage(Context context,Intent intent){
// ... some code ...
if(extras.getString(message)!= null& ; extras.getString(message)。length()!= 0){
createNotification(context,extras);
}
// ...一些代码...


We are developing a cordova based android application which has chat capability. We are sending test chat messages from a server and we received the messages just fine when the app is in foreground.

We would like to get a notification about chat message when app is in background. However we are not getting any Push Notification about chat message.

The steps we followed are mentioned below. Kindly let us know the mistake we're making.

We have referred this link to get notification on device when app is in background.

We use cordova PushPlugin to register device for push notification. And register device using below code

 pubnub.mobile_gw_provision ({
     device_id: 'A655FBA9931AB',
     op: 'add',
     gw_type: 'gcm', // or 'apns'
     channel: 'my_chat',
     callback: mySuccessCallback,
     error: myErrorCallback,
 });

We get the Push Notification if we programmatically send use the GCM device id to send Push notification from our server using GCM API.

We receive notification alert from pubnub in onNotificationGCM method of PushPlugin when application is in foreground.

We have also configured GCM server API key in admin console and enabled pubnub push notification.

I am using below Python code to publish the Chat:

_pubnub = Pubnub(publish_key='our-publish-key',
subscribe_key='our-sub-key')

channel_name = 'here-is-channel-string'
data=dict(
    pn_gcm=dict(data=dict(
        title_for_mobile='PN',
        summary_for_mobile=['Hi, test']
        )
    ),
    text='what is your dob?',
    sender=dict(name='Jon Snow', id='yyyyyyyy'),
    meta=dict(job=dict(id='zzzzzzzz'))
)

_pubnub.publish(channel_name, data)

Getting push notification of incoming chat message when application is in background is a key functionality of my application.

Please let me know what I am doing wrong?

解决方案

I had also raised a support request regarding this on Pubnub's support. After some nice replies from guys at Pubnub, we were able to resolve it.

We were mislead by this documentation, and we were using

"pn_gcm": {
  "data": {
      "title_for_mobile": "Test",
      "summary_for_mobile": [ "Hi" ]
   }
}

Instead, we should have used.

{
  "message": "This is some text",
  "pn_gcm": { 
     "data": {
         "title": "Demo wpush", 
         "message":"This is a pushnotification"
     }
   },
   "pn_debug": "true"
} 

Because Cordova PushPlugin is expecting message key from GCM.

// GCMIntentService.java
@Override
protected void onMessage(Context context, Intent intent) {
    //.... some code ...
    if (extras.getString("message") != null && extras.getString("message").length() != 0) {
          createNotification(context, extras);
    }
    //... some code ...

这篇关于Pubnub推送通知不适用于跨平台移动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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