2013-10-31 111 views
0

我試圖發送推送通知給我的寡婦手機8應用程序(瓷磚通知)。這是來自MPNS的響應:通知狀態:抑制notificationChannelStatus:活動,設備連接狀態:已連接。我已經檢查了服務器響應代碼,並且發現了以下解釋:MPNS推送通知服務器返回作爲通知狀態返回抑制

推送通知已被推送 通知服務接收和刪除。如果 通知類型無法通過調用BindToShellTile或 BindToShellToast客戶端應用程序

啓用,可能會發生被抑制的狀態這是我在客戶端代碼和我打電話BindToShellTile方法 - 它是越來越援引第一次該應用程序已安裝。

HttpNotificationChannel pushChannel; 
string channelName = "TileSampleChannel"; 
pushChannel = HttpNotificationChannel.Find(channelName); 
if (pushChannel == null) { 
    pushChannel = new HttpNotificationChannel(channelName); 
    // Register for all the events before attempting to open the channel. 
    pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated); 
    pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred); 
    pushChannel.Open();    
    pushChannel.BindToShellTile(); 
} else {   
    pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated); 
    pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);      
    System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString()); 
    MessageBox.Show(String.Format("Channel Uri is {0}", 
    pushChannel.ChannelUri.ToString())); 
} 

而且我能夠成功獲取通道URI。爲什麼我總是被壓制的狀態?我已經在設備上進行過測試,並且已經檢查過電池電量不低。該瓷磚也固定開始屏幕。

這是我的XML

string tileMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + 
       "<wp:Notification xmlns:wp=\"WPNotification\">" + 
        "<wp:Tile>" + 
         "<wp:BackgroundImage>" + TextBoxBackgroundImage.Text + "</wp:BackgroundImage>" + 
         "<wp:Count>" + TextBoxCount.Text + "</wp:Count>" + 
         "<wp:Title>" + TextBoxTitle.Text + "</wp:Title>" + 
         "<wp:BackBackgroundImage>" + TextBoxBackBackgroundImage.Text + "</wp:BackBackgroundImage>" + 
         "<wp:BackTitle>" + TextBoxBackTitle.Text + "</wp:BackTitle>" + 
         "<wp:BackContent>" + TextBoxBackContent.Text + "</wp:BackContent>" + 
        "</wp:Tile> " + 
       "</wp:Notification>"; 
+0

你可以顯示你的XML消息嗎? –

+0

@kubakista我已經添加了我的XML .. –

回答

2

確認您的通知內容長度,內容類型和標題都是正確的。

您需要的下列頭瓷磚通知:

sendNotificationRequest.Headers.Add("X-WindowsPhone-Target", "token"); 
sendNotificationRequest.Headers.Add("X-NotificationClass", "1"); 

和頭前,按以下步驟設置內容長度和類型:

sendNotificationRequest.ContentLength = notificationMessage.Length; 
sendNotificationRequest.ContentType = "text/xml"; 

如果不正確地指定的頭可以使通知狀態爲「已禁用」。這可能是有用的。

+0

謝謝..問題是與notificationMessage.Length,我不確定使用的編碼..它的工作! –

+0

你能告訴我那裏有什麼問題嗎?我也與編碼類型苦苦掙扎 – maxchirag