0

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

推送通知服务已接收并删除了推送通知。如果未通过在客户端应用程序中调用 BindToShellTile 或 BindToShellToast 启用通知类型,则可能会出现 Suppressed 状态

这是我在客户端的代码,我正在调用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>";
4

1 回答 1

2

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

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

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

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

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

如果您没有正确指定可以将通知状态设置为已抑制的标题。这可能很有用。

于 2013-11-22T12:34:59.177 回答