0
votes

I have a error when I invoke a Worklight procedure with the properties for APNS notification, specifically - sound.

The error in Eclipse:

[ERROR ] FWLSE0099E: An error occurred while invoking procedure [project ExamplePushTags]PushTagAdapter/sendNotificationFWLSE0100E: parameters: [project ExamplePushTags] TypeError: Cannot set property "apns" of undefined to "[object Object]" (PushTagAdapter-impl.js#30)

In the navigator (safari) appears this:

{
       "errors": [
          "Ecma Error: TypeError: Cannot set property \"apns\" of undefined to \"[object Object]\" (PushTagAdapter-impl.js#30)"
       ],
       "info": [
       ],
       "isSuccessful": false,
       "warnings": [
       ]
    }

Code of function in my adapter 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"};
}

Note: If I comment this line, I don't have problems and the notification works but I need sound in each notification.

I am using Worklight 6.2

1

1 Answers

1
votes

Your are missing the definition of notification.settings as an object

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

For more info:

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