使用APNs证书进行推送。 AWS SNS支持iOS APNs,可以使用APNs证书将消息推送到iOS设备。MDM证书只能用于推送企业应用程序。下面是使用APNs证书的示例代码:
var sns = new AWS.SNS();
var publishParams = {
Message: 'Hello World!',
TargetArn: 'arn:aws:sns:us-west-2:123456789012:endpoint/APNS/exampleapp/c30051eb-01f5-43a3-8090-8a862d06b766',
MessageStructure: 'json',
MessageAttributes: {
'AWS.SNS.MOBILE.APNS.PRIORITY': { DataType: 'String', StringValue: '10' },
'AWS.SNS.MOBILE.APNS.PUSH_TYPE': { DataType: 'String', StringValue: 'background' }
}
};
sns.publish(publishParams, (err, data) => {
if (err) {
console.error('Failed to send push notification:', err);
} else {
console.log('Push notification sent:', data);
}
});
在TargetArn字段中,将endpoint设置为APNS,并将应用程序标识符和设备令牌设置为字符串。然后,将MessageAttributes设置为有关消息的其他信息。
此外,还应确保使用的APNs证书与您的SNS应用程序完全相同。您可以使用Apple的控制台验证证书。