2012-06-28 53 views
0

我想實現這樣的http://dotnettrain.blogspot.co.uk/2011/07/push-notifications-in-windows-phone-75.html推送通知基本面

我送,並在同一頁面接收。 A.xaml

有效載荷我試圖發送:在GetToastPayLoad

string message = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + 
    "<wp:Notification xmlns:wp=\"WPNotification\">" + 
     "<wp:Toast>" + 
     "<wp:Text1>New Link Request</wp:Text1>" + 
     "<wp:Text2>"+data.Title+"</wp:Text2>" + 
     "</wp:Toast>" + 
    "</wp:Notification>"; 

而對於HttpRequest的標題是: -

......................................... 
    var request = (HttpWebRequest)WebRequest.Create(new Uri(channelUri)); 
       request.Method = "POST"; 
       request.ContentType = "text/xml"; 
       payload = GetToastPayload(data); 
       request.Headers.Add("X-WindowsPhone-Target", "toast"); 
       request.Headers.Add("X-NotificationClass", "2"); 
       } 

我能夠捕捉A.xaml響應如OnToastNotificationReceived並在消息框中打印詳細信息。

但是,當我刪除事件處理程序,我沒有得到我的正在運行的應用程序中的任何通知。

如何以正常方式接收和顯示正常的吐司通知?

* 我應該怎麼做,使這種普遍的,說我想無論用戶是要顯示:A.xaml,B.xaml,C.xaml *

回答

1

?收到通知的任何地方嘗試把你的代碼App()構造函數中的App.xaml.cs,因爲它是在Sending toast notifications on Windows Phone 7

Toast通知表明,當你的應用程序正在運行,所以你將不能夠向他們展示這種方式(即使不顯示你嘗試手動執行ToastPrompt)所以你在這種情況下應該使用ShellToastNotificationReceived來處理通知。

當你的應用程序沒有運行時,你應該看到吐司通知顯示。