如何在worklight中为Windows Phone 8配置未经过身份验证的推送通知

时间:2015-11-03 10:49:21

标签: windows-phone-8 notifications ibm-mobilefirst

我已经在Android和IOS中配置了推送通知,并且它运行良好。但是当我在工作灯中为Windows Phone 8配置了非认证推送通知时,它无效。我按照下面的MobileFirst文档运行Windows Phone 8的推送通知:

https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-7-1/foundation/notifications/push-notifications-overview/push-notifications-in-hybrid-applications/#setupWP8

另外我想知道,对于基于订阅的推送通知,推荐哪种通知用于Windows Phone 8,即非认证推送或认证推送?

以下是我的代码:

adapter.js

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

if (userSubscription==null){
    return { result: "No subscription found for user :: " + userId };
}
var notification={};
notification.MPNS={};
var badgeDigit = 1;

var notification = WL.Server.createDefaultNotification(notificationText, badgeDigit, {custom:"data"});
notification.MPNS.toast={};
notification.MPNS.toast.text1 = "Toast title";
notification.MPNS.toast.text2 = "Toast content";
WL.Logger.debug("submitNotification >> userId :: " + userId + ", text :: " + notificationText);

WL.Server.notifyAllDevices(userSubscription, notification);


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

应用descriptor.xml

<windowsPhone8 version="1.0">
    <uuid>5747-54938-fjhg-f459-844h-fhkj</uuid>
</windowsPhone8>

请帮我看看Windows Phone 8推送通知。

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++ 在“application-descriptor.xml”中添加推送发送者ID后。推送通知正在Windows Phone8上工作。但是面临在Windows Phone8上接收广播通知的问题。

broadcastAdapter 的.js

function sendBroadcastNotification(applicationId, notificationText) { 
var notificationOptions = {}; 
notificationOptions.message = {}; 
notificationOptions.message.alert = notificationText; 
WL.Server.sendMessage(applicationId, notificationOptions); 
return { 
result : "Notification sent to all users." 
 }; 
}

main.js 中的客户端代码:

if(WL.Client.Push){ 
WL.Client.Push.onMessage = function (props, payload) { 
navigationFromNotification = true; 
WL.SimpleDialog.show("Tag Notifications", "Provider notification data: " +    JSON.stringify(props), [ { 
text : 'Close', 
handler : function() { 
WL.SimpleDialog.show("Brodcast Notifications", "Application notification data: " + JSON.stringify(payload), [ { 
text : 'Close', 
handler : function() { 
window.location.href="#/home/2"; 
 } 
}]); 
 } 
}]); 
}; 
}

我是否需要添加任何内容以在Windows Phone8上接收广播通知

2 个答案:

答案 0 :(得分:2)

您链接到的文档明确提到添加一个空的pushSender元素,并且从application-descriptor.xml的代码片段中可以看到 - 您没有这样做。基本上,您没有将应用程序配置为使用推送通知(!)。

<windowsPhone8 version="1.0">
    <uuid>auto-generated by the platform</uuid>
    <pushSender /> 
</windowsPhone8>

经过身份验证或未经过身份验证的推送与基于用户的订阅无关 你可以使用任何一个。 MS的唯一限制是,未经过身份验证的每天限制为500条消息,而经过身份验证的限制(并且更加安全)。

答案 1 :(得分:1)

a)MPNS推送通知可以在未经身份验证或验证的模式下运行。在未经身份验证的模式下,通过Microsoft推送通知服务允许的通知的数量和频率受到限制(未经身份验证的推送通知目前限制为每个通道每天500个)。

MSDN documentation

IBM MobileFirst支持经过身份验证和未经身份验证的MPNS推送。

b)如果是标签/广播MPNS通知,默认情况下,通知会显示在应用程序磁贴中。要在应用程序处于前台或作为Toa​​st通知时显示通知,请将以下代码添加到适配器中的sendBroadcastNotification()方法:

notificationOptions.settings = {};
notificationOptions.settings.mpns ={};
notificationOptions.settings.mpns.raw = {};
notificationOptions.settings.mpns.raw.payload= {'payload' : notificationText};

notificationOptions.settings.mpns.toast ={};
notificationOptions.settings.mpns.toast.text1 = 'Title';
notificationOptions.settings.mpns.toast.text2= notificationText;

有关完整的code

,请参阅TagNotifications示例