未从通知托盘中获取捆绑包中的 Pubnub 有效负载。当应用程序被杀死

Not getting Pubnub payload in bundle from Notification tray. When app is killed

我在我的一个项目中集成了 pubnub API。我正在尝试获取我在有效负载中发送的数据包。我已经为推送通知添加了 FCM。我在所有情况下都会收到推送通知,但在应用程序被终止或在后台运行时不会收到捆绑包数据。当应用程序在前台时已经获取有效负载对象,但当应用程序在后台或被杀死时未获取任何数据。

有效载荷 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"
}

有效载荷 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
}

当应用程序在前台时我收到通知对象,但当应用程序在后台或被杀死时我没有收到通知对象。(获取一些 FCM 默认对象)

我试图在从通知托盘启动应用程序时获取捆绑包中的通知对象

回答 像这样制作 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"
  }
}
}

您需要添加 data 以及您希望通过推送接收的信息到 pn_gcmpn_(gcm|apns) 之外的信息(包括 tjpse)将作为常规消息传递

留言可以如下:

使用 notification:

{
   "pn_gcm":{
      "notification":{
         "title":"Chat invitation",
         "body":"John invited you to chat",
         "sound":"default"
      }
   }
}

或使用data:

{
  "pn_gcm" : {
    "data" : {
      "room" : "Portugal vs Denmark",
      "body" : "great match!"
    }
  }
}

或两者:

{
  "pn_gcm" : {
    "notification": {
      "title":"Portugal vs Denmark",
      "body":"great match!"
    },
    "data" : {
      "room" : "Portugal vs Denmark",
      "body" : "great match!"
    }
  }
}

有关 datanotification 之间差异的解释,请阅读官方 FCM 文档,About FCM messages

另请参阅: Why are my FCM push notifications not working?