【发布时间】:2013-10-09 14:36:22
【问题描述】:
我想检查我的推送通知实现是否正确。
每次我打开我的应用程序时(实际上我只在特定页面上注册推送通道,所以每次我从该页面来回访问时)都会创建一个新的推送通道 URI,并将其存储在我的移动服务中数据库发送推送通知。这对我来说似乎不正确,因为每次打开应用程序/页面时都会生成一个新的推送通道 URI,因此通道 URI 列表只会随着使用我的应用程序的每个设备而增长和增长。我假设您创建了一个推送频道,存储频道 URI 并根据需要推送到它。我将在此处说明我使用的是原始推送通知。
我知道推送通道会经常过期,但对我来说,每次我退出应用程序/页面时都会发生这种情况,因此当调用 onNavigateTo 时,我发现推送通道确实存在并且总是创建一个新的通道 URI .它是否正确?
我的代码如下:
受保护的覆盖无效 OnNavigatedTo(NavigationEventArgs e) { registerPushChannel(); }
private void registerPushChannel()
{
// The name of our push channel.
string channelName = "RawSampleChannel";
// Try to find the push channel.
pushChannel = HttpNotificationChannel.Find(channelName);
// If the channel was not found, then create a new connection to the push service.
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.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(PushChannel_HttpNotificationReceived);
pushChannel.Open();
}
else
{
// The channel was already open, so just register for all the events.
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
pushChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(PushChannel_HttpNotificationReceived);
// code which passes the new channel URI back to my web service
}
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
pushChannel.Close();
}
为了澄清,应用程序已打开,推送频道已注册,频道 uri 已保存在我的 Web 服务中。然后,Web 服务将通知发送到通道 uri。当我退出应用程序或页面并返回到它时,会找到推送通道,但会创建一个新的通道 uri,我再次将其保存到我的 Web 服务中。我的频道表实际上一直在增长。
那么,它应该以这种方式处理不断生成的新频道 URI 吗?这对我来说有点没有意义。我不确定 toast 和 tile 通知是如何工作的,但我假设当应用程序关闭时通道 URI 需要是静态的,以便在应用程序关闭时继续接收通知,但也许这可能是 bindtoast 和 bindtotile 的功能等等我所做的是正确的,因为它与原始通知有关。
【问题讨论】:
-
我正在努力解决我实际放入“PushChannel_ChannelUriUpdated”的内容。你能举个例子吗?
标签: c# windows-phone-8 push-notification mpns