用AWS Amplify iOS接收消息的APNS消息结构是什么,以便正确触发onNotification事件?

问题描述

我通过@ 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相同/自定义有效负载不起作用。

我根据以下内容增强了AppDelegate https://github.com/react-native-push-notification-ios/push-notification-ios#augment-appdelegate

有人知道amplify是否期望某个有效负载来触发事件?还是其他原因导致这种情况..

到目前为止已测试的结构:

SNS自定义结构

  "APNS_SANDBox": "{\"aps\":{\"alert\":\"Sample message for iOS development endpoints\"}}"
}

Pinpoint原始消息

{
    "APNSMessage": {
        "aps": {
            "alert": ""
        }
    },"GCMMessage": {
        "data": {
            "message": ""
        }
    },"ADMMessage": {
        "data" : {
            "message": ""
        }
    },"BaiduMessage": {
        "title":"","description": ""
    }
}

解决方法

解决方案是添加内容可用的内容和其他数据,以访问放大PushNotification的iOS中的标题,正文和数据。

{
  aps: {
    alert: {
      title: "title",body: "message"
    },"content-available": "1",key1: "value",key2: "value",},}

字符串化

"{\"aps\":{\"alert\":{\"title\":\"title\",\"body\":\"message\"},\"content-available\":\"1\",\"key1\":\"value\",\"key2\":\"value\"}}"