0

我试图找出通过天蓝色的移动服务中的通知中心向Windows Phone用户发送推送通知的方式。我尝试了几种这样的方式。但没有发送消息。在天蓝色的移动服务中通过通知中心发送推送通知

hub.mpns.sendToast("PushChannel", template, sendComplete); 

登记服务WP我做过这样的:

var channel = HttpNotificationChannel.Find("cQuestPushChannel"); 
if (channel == null){ 
    channel = new HttpNotificationChannel("cQuestPushChannel"); 
    channel.Open(); 
    channel.BindToShellToast(); 
} 

string[] tagsToSubscribeTo = { "xxx" }; 

channel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(async (o, args) => 
     { 
      var hub = new NotificationHub("***", "***"); 
      await hub.RegisterNativeAsync(args.ChannelUri.ToString()); 
     }); 

此登记工作正常时,我可以在蔚蓝在调试发送测试通知。

我做错了什么?

除此之外,如何在函数中添加一些标签来发送通知?

回答

0

经过一番研究,我找到了发送推送通知给wp8的正确方法。有很好的例子和解释here

基本上这里是功能是什么使通知和发送到标记的设备。

function sendToastHubMpns(text1, text2, tagExpression) 
{ 
    var azure = require("azure"); 
    var notificationHubService = azure.createNotificationHubService('hub_name', 
'hub_key'); 

    var toast = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + 
    "<wp:Notification xmlns:wp=\"WPNotification\">" + 
     "<wp:Toast>" + 
      "<wp:Text1>" + text1 + "</wp:Text1>" + 
      "<wp:Text2>" + text2 + "</wp:Text2>" + 
     "</wp:Toast> " + 
    "</wp:Notification>"; 

    notificationHubService.mpns.send(tagExpression, toast, "toast", 2, function(error) { 
    if (error) { 
     console.error(error); 
    }}); 
} 

我家会在未来帮助别人。非常感谢Geoff和他的博客。