使用 MobileFirst Platform 6.3,
我正在从WL.Server
实现sendMessage
API,用于将通知推送到所有设备(Push.ALL
)。
通知已成功推送到设备中,但它不会触发警报,如 NotifyAllDevice (如推送通知的示例项目所示)。
在通知到达我的设备后,我该怎么做才能触发包含消息的对话框?
function sendMessage(msg){
var notificationOptions = {};
notificationOptions.type = 0;
notificationOptions.message = {};
notificationOptions.message.alert = msg;
notificationOptions.target = {};
notificationOptions.target.platform = ['G','A'];
// set notification properties for GCM
notificationOptions.settings = {};
notificationOptions.settings.gcm = {};
notificationOptions.settings.gcm.sound = "default";
// set notification properties for APNS
notificationOptions.settings.apns = {};
notificationOptions.settings.apns.sound = "default";
//WL.Server.notifyAllDevices(userSubscription, notification);
WL.Server.sendMessage("PushNotifications", notificationOptions);
return {
result: "Notification sent to user :: "
};
}
对于基于广播/标签的消息,通知在客户端/应用程序上接收。 在回调中
WL.Client.Push.onMessage(props, payload)
有关 API 的更多信息,请访问 -http://www-01.ibm.com/support/knowledgecenter/SSZH4A_6.2.0/com.ibm.worklight.apiref.doc/html/refjavascript-client/html/WL.Client.Push.html%23onMessage
下面介绍了如何定义回调并在应用中显示
WL.Client.Push.onMessage = function(props, payload) {
alert("broadcastReceived invoked");
alert("props :: " + JSON.stringify(props));
alert("payload :: " + JSON.stringify(payload));
};