2015-10-27 38 views
0

添加自定义属性我有一个小问题,我需要为我目前使用MobileFirst 7.1.0自定义参数/属性添加到通知WL.Server.notifyAllDevices需要在通知

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 

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

回答

0

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

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

+0

其实事情是,这个badgeDigit适用于iPhone。但我的情况是不同的。这是一个详细的范围。我会是伟大的Idan如果我可以得到如何定制notifyAllDevice参数发送'content-available:1'作为参数。现在notifyAlllDevices或createdefaultnotification函数不允许任何其他参数。如何添加或将此自定义参数添加到该功能...需要帮助人 –

+0

那么,为什么你不提到你的场景是什么? –

+0

好的,让我告诉你 –