如何通过 ASPN 的 SNS 推送通知发送附加参数?

问题描述 投票:0回答:1

我正在使用带有 nodejs(GCM、APNS)的 SNS 为 android 和 iOS 发送推送通知。我的有效载荷看起来像这样:

    const payload = {
      default: body,
      GCM: {
        notification: {
          body,
          title,
        },
        data: {
          type
        },
      },
      APNS: {
        aps: {
          alert: {
            title,
            body,
          },
        },
        data: {
          type
        },
      },
    };

    payload.GCM = JSON.stringify(payload.GCM);
    payload.APNS = JSON.stringify(payload.APNS);

    return JSON.stringify(payload);

移动设备收到带有标题和正文的通知,但 APNS 对象中不存在数据内部类型。是不是对象结构错了?

node.js apple-push-notifications amazon-sns
1个回答
0
投票

对于

APNS
,你可以尝试像这样解压你的数据对象:

    const payload = {
      default: body,
      GCM: {
        notification: {
          body,
          title,
        },
        data: {
          type
        },
      },
      APNS: {
        aps: {
          alert: {
            title,
            body,
          },
        },
        type,
      },
    };

找不到任何可靠的答案,但我读过的关于这个主题的所有内容都表明 APNS JSON 有效负载仅支持 "aps" 对象之外的自定义

string
键值对:

https://docs.aws.amazon.com/sns/latest/dg/sns-send-custom-platform-specific-payloads-mobile-devices.html

例如

{
  "APNS": "{\"aps\":{\"content-available\":1},\"Foo1\":\"Bar\",\"Foo2\":123}"
}

例如

 'APNS' : JSON.stringify({
   'aps' : { 
     'alert' : $title,
     'badge' : '0',
     'sound' : 'default'
   },
   'id' : '123',
   's' : 'section',
}),
© www.soinside.com 2019 - 2024. All rights reserved.