Search code examples
ibm-mobilefirst

WL.Server.notifyAllDevices need to add custom property in notification


I have a little problem that I need to add custom parameter/property to the notification

function submitNotification(userId, notificationText){
    var userSubscription = WL.Server.getUserNotificationSubscription('PushAdapter.PushEventSource', userId);

    if (userSubscription==null){
        return { result: "No subscription found for user :: " + userId };
    }

    var badgeDigit = 1;

    var notification = WL.Server.createDefaultNotification(notificationText, badgeDigit, {custom:"data"});

    WL.Logger.debug("submitNotification >> userId :: " + userId + ", text :: " + notificationText); 
    WL.Server.notifyAllDevices(userSubscription, notification); 

    return { 
        result: "Notification sent to user :: " + userId 
    };
}


// need to pass custom property content-available:1 but not in payload

As I am currently using MobileFirst 7.1.0. The purpose of this enhancement is I need to update notification badge in iPhone App when App is in not started stage. By Adding content-available:1 at 1st level of notification can help to complete it. Any Luck ?


Solution

  • I guys. Thanks for all your concerns. Here is the answer:

    function submitNotification(userId, notificationText){
        var userSubscription = WL.Server.getUserNotificationSubscription('PushAdapter.PushEventSource', userId);
    
        if (userSubscription==null){
            return { result: "No subscription found for user :: " + userId };
        }
    
        var badgeDigit = 1;
    
        var notification = WL.Server.createDefaultNotification(notificationText, badgeDigit, {custom:"data"});
        //notification = {alert:"test in here",
        //              badge:4,
        //              payload: {custom:"data1"},
        //              "content-available":1};
    
        notification.APNS.type = "MIXED" ;
        notification.APNS.badge = 89;
        notification.APNS.alert = "in here";
        notification.APNS['content-available'] = 1;
    
        WL.Logger.debug("submitNotification >> userId :: " + userId + ", text :: " + notificationText); 
        WL.Server.notifyAllDevices(userSubscription, notification); 
    
        return { 
            result: "Notification sent to user :: " + userId 
        };
    }