我想检查推送通知实施是否正确。Windows Phone 8推送通知推送通道始终创建新通道uri
每当我打开我的应用程序(实际上我只在特定页面上注册推送通道,所以每次我从该页面来回移动时)都会创建一个新的推送通道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,然后再次保存到我的网络服务。我的频道表实际上保持增长和增长。
那么,这是应该如何处理新的渠道URI不断产生?这对我来说没有意义。我不知道如何吐司和磁贴通知工作,但我会假设渠道URI需要是静态时,应用程序关闭,以保持接收通知,而应用程序关闭,但也许这可能是一个功能bindtotoast和bindtotile等我正在做的是正确的,因为这是与原始通知。
我正在努力与'PushChannel_ChannelUriUpdated'实际投入。你能举个例子吗? – creatiive