[英]Not getting Pubnub payload in bundle from Notification tray. When app is killed
I have integrated pubnub API in one of my project.我在我的一个项目中集成了 pubnub API。 I am trying to get bundle of data that i have sent in payload.我正在尝试获取我在有效负载中发送的数据包。 I have added FCM for push notification.我为推送通知添加了 FCM。 I am getting push notification in all cases but not getting bundle data when app is killed or in background.我在所有情况下都收到推送通知,但在应用程序被杀死或在后台时没有收到捆绑数据。 Already getting payload object when app is in foreground but not getting any data when app is in background or killed.当应用程序处于前台时已经获得有效负载 object 但在应用程序处于后台或被杀死时未获取任何数据。
Payload 1:有效载荷 1:
{
"pn_gcm": {
"notification": {
"title": "Barack Obama",
"body": "12",
"channelName": "Hell 4_656"
}
},
"firstName": "Barack",
"lastName": "Obama",
"displayName": "Barack Obama",
"profileImageUrl": "abcURL",
"userId": "173",
"type": "sender",
"time": "1615958943297",
"message": "12"
}
PayLoad 2:有效载荷 2:
{
pn_gcm={
notification={
title=BarackObama,
body=Hello,
image=Hell4_656
}
},
firstName=Barack,
lastName=Obama,
displayName=BarackObama,
time=1615958740553,
type=sender,
message=Hello,
profileImageUrl=abcURL,
userId=173
}
I am getting notification object when app is in foreground but not getting any of them when app is in background or killed.(Getting some FCM default object)当应用程序在前台时,我收到通知 object 但在应用程序在后台或被杀死时没有收到任何通知。(获取一些 FCM 默认对象)
I am trying to get notification object in bundle when launch app from Notification tray从通知托盘启动应用程序时,我试图在捆绑包中收到通知 object
Answer Made JSON payload like this:答案使 JSON 有效载荷如下:
{
"pn_gcm": {
"notification": {
"title": "Barack Obama",
"body": "18"
},
"body": {
"channelName": "Hell 5_657",
"firstName": "Barack",
"lastName": "Obama",
"displayName": "Barack Obama",
"profileImageUrl":
"http://3.137.127.137/quiqle/uploads/profile/1615523786_4866.jpg",
"userId": "173",
"type": "sender",
"time": "1615965488916",
"message": "18"
}
}
}
You need to add data
with information which you want to receive with push into pn_gcm
.您需要将data
与您希望通过 push 接收的信息一起添加到pn_gcm
中。 Information outside of pn_(gcm|apns)
(including tjpse) will be delivered as regular messages pn_(gcm|apns)
之外的信息(包括 tjpse)将作为常规消息传递
Message can be as follows:消息可以如下:
using notification
:使用notification
:
{
"pn_gcm":{
"notification":{
"title":"Chat invitation",
"body":"John invited you to chat",
"sound":"default"
}
}
}
Or using data
:或使用data
:
{
"pn_gcm" : {
"data" : {
"room" : "Portugal vs Denmark",
"body" : "great match!"
}
}
}
or both:或两者:
{
"pn_gcm" : {
"notification": {
"title":"Portugal vs Denmark",
"body":"great match!"
},
"data" : {
"room" : "Portugal vs Denmark",
"body" : "great match!"
}
}
}
For an explanation on the different between data
and notification
, please read the official FCM docs, About FCM messages .关于data
和notification
的区别,请阅读 FCM 官方文档, 关于 FCM 消息。
See also: Why are my FCM push notifications not working?另请参阅: 为什么我的 FCM 推送通知不起作用?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.