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和他的博客。