WL.Server.notifyAllDevices 需要在通知中添加自定义 属性
WL.Server.notifyAllDevices need to add custom property in notification
我有一个小问题,我需要将自定义 parameter/property 添加到通知
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。此增强功能的目的是当应用程序处于未启动阶段时,我需要更新 iPhone 应用程序中的通知标志。通过在通知的第一级添加 content-available:1 可以帮助完成它。运气好吗?
徽章由您代码中的变量决定:
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
伙计们。谢谢大家的关心。
答案如下:
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
};
}
我有一个小问题,我需要将自定义 parameter/property 添加到通知
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。此增强功能的目的是当应用程序处于未启动阶段时,我需要更新 iPhone 应用程序中的通知标志。通过在通知的第一级添加 content-available:1 可以帮助完成它。运气好吗?
徽章由您代码中的变量决定:
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
伙计们。谢谢大家的关心。 答案如下:
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
};
}