当我使用APNS通知的属性调用Worklight过程时出现错误,特别是声音。
Eclipse中的错误:
[错误] FWLSE0099E:调用过程时发生错误 [project ExamplePushTags] PushTagAdapter / sendNotificationFWLSE0100E: 参数:[project ExamplePushTags] TypeError:无法设置属性 " APNS"未定义到" [对象对象]" (PushTagAdapter-impl.js#30)
在导航器(safari)中显示:
{
"errors": [
"Ecma Error: TypeError: Cannot set property \"apns\" of undefined to \"[object Object]\" (PushTagAdapter-impl.js#30)"
],
"info": [
],
"isSuccessful": false,
"warnings": [
]
}
我的适配器PushTagAdapter-impl.js中的函数代码:
var applicationId = "ExamplePushTags";
function sendNotification (tag, notificationText, url) {
var notification = {};
notification.message = {};
notification.message.alert = notificationText;
notification.target = {};
notification.target.tagNames = [tag];
//set notification properties for APNS
//error in this lines of code
notification.settings.apns = {};
notification.settings.apns.sound = 'sounds-865-fallin.mp3';
WL.Server.sendMessage(applicationId, notification);
WL.Logger.info("Notificacion enviada exitosamente " + JSON.stringify(notification));
return { result: "Notification sent"};
}
注意:如果我对此行发表评论,我就不会遇到问题并且通知有效但我在每个通知中都需要声音。
我正在使用Worklight 6.2
答案 0 :(得分:1)
您遗漏了notification.settings
作为对象的定义
var applicationId = "ExamplePushTags";
function sendNotification (tag, notificationText, url) {
var notification = {};
notification.message = {};
notification.message.alert = notificationText;
notification.target = {};
notification.target.tagNames = [tag];
// missing this
notification.settings = {};
//set notification properties for APNS
//error in this lines of code
notification.settings.apns = {};
notification.settings.apns.sound = 'sounds-865-fallin.mp3';
// APNS payload here
notification.settings.apns.payload = {};
WL.Server.sendMessage(applicationId, notification);
WL.Logger.info("Notificacion enviada exitosamente " + JSON.stringify(notification));
return { result: "Notification sent"};
}
欲了解更多信息: