无法从未定义的Adapter-impl.js读取属性\“apns \”

时间:2015-03-04 20:11:25

标签: apple-push-notifications ibm-mobilefirst worklight-adapters

当我使用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

1 个答案:

答案 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"};
}

欲了解更多信息:

http://www-01.ibm.com/support/knowledgecenter/SSZH4A_6.2.0/com.ibm.worklight.apiref.doc/html/refjavascript-server/html/WL.Server.html?cp=SSZH4A_6.2.0%2F10-1-0-1-2