我想检查我的推送通知实现是否正确.
每次我打开我的应用程序(实际上我只在特定页面上注册推送通道,所以每次我从该页面来回移动)都会创建一个新的推送通道URI,我将其存储在我的移动服务数据库中以发送推送通知.这对我来说似乎不正确,因为每次打开app/page时都会生成一个新的推送通道URI,因此每个使用我的应用程序的设备的通道URI列表都会增长和增长.我假设您创建了一个推送通道,存储通道URI并根据需要推送到它.我会在这里注意到我正在使用原始推送通知.
我知道推送频道每隔一段时间就会过期,但对我而言,每次我退出应用程序/页面时都会发生这种情况,因此当调用onNavigateTo时,我发现确实存在的推送频道,并且始终创建新的频道URI.它是否正确?
我的代码如下:
protected override void 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); …Run Code Online (Sandbox Code Playgroud)