WL.Server.notifyAllDevices需要在通知中添加自定义属性

时间:2015-10-27 01:19:38

标签: ibm-mobilefirst

我有一个小问题,我需要在通知中添加自定义参数/属性

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

因为我目前正在使用MobileFirst 7.1.0。此增强功能的目的是当App处于未启动阶段时,我需要在iPhone App中更新通知徽章。通过添加内容可用:1在第1级通知可以帮助完成它。运气好吗?

2 个答案:

答案 0 :(得分:1)

我们。感谢您的所有关注。 这是答案:

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

答案 1 :(得分:0)

徽章由代码中的变量决定:

var badgeDigit = 1;

将此更改为另一个号码,以及当通知到达设备时将在应用程序图标上显示的内容。

请注意,MobileFirst不提供任何内置支持来减少您的号码。这意味着在您的应用程序逻辑中,您将需要使用API​​方法WL.Badge来更改它:http://www-01.ibm.com/support/knowledgecenter/SSHS8R_7.1.0/com.ibm.worklight.apiref.doc/html/refjavascript-client/html/WL.Badge.html?cp=SSHS8R_7.1.0%2F10-0-0-1-4