MPNS推送通知服务器返回被抑制为通知状态

时间:2013-10-31 11:38:21

标签: c# windows-phone-8 push-notification mpns

我正在尝试向我的寡妇手机8应用程序发送推送通知(平铺通知)。这是来自MPNS的响应:通知状态:抑制notificationChannelStatus:活动,deviceConnectionStatus:已连接。我检查了服务器响应代码,我找到了以下解释:

  

推送通知已被Push接收和删除   通知服务。如果是,则可以发生抑制状态   通过调用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>";

1 个答案:

答案 0 :(得分:2)

验证您的通知内容长度,内容类型和标题是否正确。

对于平铺通知,您需要以下标题:

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

并在标题之前,设置内容长度和类型如下:

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

如果未正确指定标题,可以将“通知状态”设置为“已抑制”。这可能很有用。