向iOS推送通知成功,但显示为';失败';
我正在使用APN模块向iOS发送推送通知。这一切似乎都很好,但我总是得到“失败”作为回应后,发送的消息,事实上,我在电话上得到的消息(所以它不应该是“失败”) 为什么响应显示为“失败”以及如何修复它向iOS推送通知成功,但显示为';失败';,ios,push-notification,apple-push-notifications,Ios,Push Notification,Apple Push Notifications,我正在使用APN模块向iOS发送推送通知。这一切似乎都很好,但我总是得到“失败”作为回应后,发送的消息,事实上,我在电话上得到的消息(所以它不应该是“失败”) 为什么响应显示为“失败”以及如何修复它 var apn = require('apn'); var options = { token: { key: "keys/AuthKey_123.p8", keyId: "123", teamId: "teamA" }, production: false };
var apn = require('apn');
var options = {
token: {
key: "keys/AuthKey_123.p8",
keyId: "123",
teamId: "teamA"
},
production: false
};
var json_message = {
"aps" : {
"alert" : {
"title" : "This is title",
"body" : "This is body",
}
};
var apnProvider = new apn.Provider(options);
var deviceToken = "device token";
var note = new apn.Notification();
note.expiry = Math.floor(Date.now() / 1000) + 3600; // Expires 1 hour from now.
note.badge = 3;
note.sound = "ping.aiff";
note.alert = json_message.aps.alert.body;
note.payload = json_message;
note.topic = "com.test";
apnProvider.send(note, deviceToken).then( (result) => {
console.log(result);
console.log("\n*** Response: ***\n");
console.log(JSON.stringify(result, null, 2));
});
您的
json_消息
缺少一个结束括号。这是真的,但即使使用非常简单的json(例如1个键和1个值),当确实成功时,也会显示相同的错误(失败)。因此,JSON不是这种情况的根本原因。。可能是什么?我肯定这不是问题所在。可能您可以检查错误对象,该对象包含有关响应中失败的更多详细信息。另外,您是否尝试仅使用便利设置器构建简单通知?