Windows phone 8 subscribeTag在windowsphone8中不工作
我在windowsphone8中实现了基于标签的推送通知,但当我执行以下代码时,我的应用程序无法注册标签 我也尝试过把Windows phone 8 subscribeTag在windowsphone8中不工作,windows-phone-8,push-notification,ibm-mobilefirst,Windows Phone 8,Push Notification,Ibm Mobilefirst,我在windowsphone8中实现了基于标签的推送通知,但当我执行以下代码时,我的应用程序无法注册标签 我也尝试过把subscribeTag放到之外的上,但我没有得到任何结果&没有成功,没有失败,什么都没有 if (WL.Client.Push) { WL.Client.Push.onReadyToSubscribe = function() { WL.Client.Push.subscribeTag("RRNEWS", {
subscribeTag
放到之外的上,但我没有得到任何结果&没有成功,没有失败,什么都没有
if (WL.Client.Push) {
WL.Client.Push.onReadyToSubscribe = function() {
WL.Client.Push.subscribeTag("RRNEWS", {
onSuccess: function () {
alert("Tag registered");
},
onFailure: function (e) {
alert("Tag registered failed" + JSON.stringify(e));
}
});
};
}else{
alert("not supported");
}
我在application descriptor.xml
中有register标记,如下所示
<tags>
<tag>
<name>RRNEWS</name>
<description>News</description>
</tag>
</tags>
其余按钮被禁用
1) Subscribe to sample-tag2
2) Unsubscribe from sample-tag1
3) Unsubscribe from sample-tag2
然后我尝试从html标记中删除禁用的属性,然后尝试按
订阅sample-tag2
但什么都没有发生
更改是适配器代码
function sendTagNotificationToWindows(applicationId, notificationText,notificationTags){
var notificationOptions = {};
var tags = notificationTags.split(",");
var notificationOptions = {};
var notification = WL.Server.createDefaultNotification(notificationText, 10);
notification.MPNS.raw = {};
notification.MPNS.raw.payload = {"custom":"data"} ;
notificationOptions.message = {};
notificationOptions.target = {};
notificationOptions.message.alert = JSON.stringify(notification);
notificationOptions.target.tagNames = tags;
// i have tried it with a notificationOptions too
WL.Server.sendMessage(applicationId, notification);
return {
result : "Notification sent to users subscribed to the tag(s): '" + JSON.stringify(notification) + "'."
};
}
错误
当我只传递通知参数时,它抛出以下错误
"Push Works Bad Request: FPWSE0005E: Invalid value was provided. Check the 'message' parameter value."
不考虑Windows Phone 8环境。以下是您需要添加到示例中的内容:
应用程序描述符.xml
添加Windows Phone 8环境后,添加一个空的pushSender
标记:
<windowsPhone8 version="1.0">
<uuid>AUTOGENERATED-GUID-NUMBER-HERE</uuid>
<pushSender/>
</windowsPhone8>
需要notificationOptions.settings.mpns.toast
,这样当应用程序关闭(退出)或在后台时,“toast”通知类型将出现在设备中
点击toast通知将启动应用程序。可选的“param”字段用于传递应用程序启动后将显示的值。toast的“param”中设置的值可以在应用程序中检索和显示
其他澄清:
- 当应用程序打开时,原始通知类型以及道具和有效载荷值可以在屏幕上看到(如果使用)
- 当应用程序位于后台并点击通知时,可以接收两种通知类型:toast或tile。两者都打开应用程序
- 当应用程序位于后台并点击应用程序图标时:
这意味着单击应用程序磁贴。应用程序启动
- 当应用程序关闭并点击通知时:点击toast会启动应用程序。点击应用程序互动程序启动应用程序
- 当应用程序关闭并点击应用程序图标时:这意味着单击应用程序磁贴。应用程序启动
我建议阅读以下MS文档以了解可用的通知类型(Toast、Tile和Raw)以及何时使用它们:
然后在以下用户文档主题(对于onMessage
)中搜索“MPN”、“toast”、“tile”或“raw”,以查看如何在应用程序中设置它们的示例:将windowsphone8环境添加到标记通知示例应用程序后是否也会失败,此处提供:--您还可以将您的客户端实现与示例的实现进行比较……我将其与版本https://github.com/MobileFirst-Platform-Developer-Center/TagNotifications/tree/release71/apps/HybridTagNotifications
但不存在windowsphone8版本,但我将其与普通文件进行了比较,到目前为止,我使用的是worklight 6.3MobileFirst*6.3;如上所述,您可以添加环境和测试。虽然示例是针对v7.1的,但是您可以简单地将实现本身复制到您的实现中。查看您的部分代码片段,它似乎与提供的示例中的代码片段不同。您是否可以查看我的编辑器我是否应该将通知变量直接传递到WL.Server.sendMessage(applicationId,notification)代码>因为它不是这样工作的,所以它是您定义的变量。。。您可以在示例中看到它的定义。我添加了一个更完整的示例。不要使用createDefault。。。当使用标记通知时,它根本不相关。如果使用标记通知,请仅遵循示例应用程序中的代码。我尝试了您的代码,但仍然没有收到任何通知
"Push Works Bad Request: FPWSE0005E: Invalid value was provided. Check the 'message' parameter value."
<windowsPhone8 version="1.0">
<uuid>AUTOGENERATED-GUID-NUMBER-HERE</uuid>
<pushSender/>
</windowsPhone8>
function sendTagNotification(applicationId, notificationText, notificationTags) {
var tags = notificationTags.split(",");
var notificationOptions = {};
notificationOptions.message = {};
notificationOptions.message.alert = notificationText;
notificationOptions.target = {};
notificationOptions.target.tagNames = tags;
notificationOptions.settings = {};
notificationOptions.settings.mpns = {};
notificationOptions.settings.mpns.toast = {};
notificationOptions.settings.mpns.toast.text1 = "New notification";
notificationOptions.settings.mpns.toast.text2 = "You have a new notification";
notificationOptions.settings.mpns.toast.param = "/MainPage.xaml?value1=54321";
WL.Server.sendMessage(applicationId, notificationOptions);
return {
result : "Notification sent to users subscribed to the tag(s): '" + notificationTags + "'."
};
}