更新:情节变厚了。我更改了我的频道名称,它突然开始工作(这意味着我的推送服务没有问题,因为我从 Microsoft 推送通知服务器获得了相同的 HTTP 响应)。
然而,对我来说,这不是一个解决方案。如果我在它不起作用时得到相同的响应,我将如何测试并知道我的用户正在收到他们的推送通知?
[原帖]
我一直在尝试将推送通知发送到我的 Windows Phone 7 设备,但我遇到了非常大的问题,我找不到任何答案。我将从 c# 代码开始。
我使用以下 C# 代码设置推送通知。
private HttpNotificationChannel channel;
private static string PUSH_CHANNEL = "MySpecialPushChannel";
private Uri PushUri = null;
private bool IsPushRegistered = false;
public void StartPushSubscription()
{
try
{
channel = HttpNotificationChannel.Find(PUSH_CHANNEL);
}
catch
{}
if (channel != null)
{
PushUri = channel.ChannelUri;
if (!channel.IsShellTileBound)
channel.BindToShellTile();
}
else
{
channel = new HttpNotificationChannel(PUSH_CHANNEL);
channel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(channel_ChannelUriUpdated);
channel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(channel_HttpNotificationReceived);
channel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(channel_ErrorOccurred);
try
{
channel.Open();
channel.BindToShellTile();
}
catch (Exception err)
{
channel = null;
IsPushRegistered = false;
// Code to try again
}
}
}
void channel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
{
PushUri = e.ChannelUri;
IsPushRegistered = true;
}
我遵循标准的 WP7 推送结构:
- 找到 HttpNotificationChannel (或开始一个新的)
- 注册事件处理程序以获取推送通知 uri
- 打开频道
- 绑定到瓷砖
- 处理通道 Uri(我们发送到我们的服务以等待我们发送推送通知时的快乐日子
好的......到目前为止一切都很好。没有错误,我得到了我的 Uri,将它发送到我的服务就好了。我将我的应用程序固定到开始屏幕,我的服务向 Uri 发送一个推送请求(仅发送计数,以便我在右上角获得一个小的推送计数)。我通过以下内容返回 HTTP 200 状态:
DeviceConnectionStatus => 已连接
NotificationStatus => 收到
订阅状态 => 活动
然后……什么都没有。我的应用程序上没有显示推送状态。我现在已经在我的设备、模拟器、另一台设备和多台服务器上尝试过,结果总是一样的。一切看起来都在工作,只是它不起作用。