我从@aws-amplify/pushnotification 设置 PushNotification.onNotification,如下所示:
if (notification.foreground) {
console.log('notification received in foreground ', notification);
} else {
console.log('notification received in background ', notification);
}
if (PushNotificationIOS !== undefined) {
notification.finish(PushNotificationIOS.FetchResult.NoData);
}
});
在Android上它工作正常。在 iOS 上,我无法触发 onNotification/onNotificationOpened 事件,尽管我收到了通知。当我通过 Pinpoint -> Test Messaging 发送“标准消息”时有一种特殊情况,它实际上触发了该功能,当我记录通知时,它看起来像这样
'notification received in background ',
{ _data:
{ remote: true,
notificationId: '45BAA2A6-8676-402E-8E6B-03A69173AC8C' },
_remoteNotificationCompleteCallbackCalled: false,
_isRemote: true,
_notificationId: '45BAA2A6-8676-402E-8E6B-03A69173AC8C',
_alert: { title: ' test', body: 'qwerty' },
_sound: undefined,
_badgeCount: undefined,
_category: undefined,
_contentAvailable: 1,
_threadID: undefined }
(在前台收到通知,但消息不包含该信息,因此它打印为背景。使用Pintpoint -> 测试消息传递 -> 标准消息时,前台/后台都会触发事件)。Pinpoint Raw 消息也不起作用。SNS 相同/自定义有效负载不起作用。
有人知道放大是否需要某个有效负载来触发事件吗?或者,如果其他原因可能导致这种情况..?
到目前为止测试的结构:
SNS 自定义结构
"APNS_SANDBOX": "{\"aps\":{\"alert\":\"Sample message for iOS development endpoints\"}}"
}
查明原始消息
{
"APNSMessage": {
"aps": {
"alert": ""
}
},
"GCMMessage": {
"data": {
"message": ""
}
},
"ADMMessage": {
"data" : {
"message": ""
}
},
"BaiduMessage": {
"title":"",
"description": ""
}
}