Windows Phone 8 push notification push channel always creates new channel uri
I wanted to check that my push notification implementation is correct.
Each time I open my app (in actual fact I register the push channel only
on a specific page so it's each time I go back and forth from that page) a
new push channel uri is created which I store in my mobile services
database to send push notifications to. This doesn't seem correct to me as
each time the app/page is open a new push channel uri is generated and so
the list of channel uri's just grows and grows for each device that uses
my app. I'd assume that you create a push channel, store the channel uri
and push to it as needed. I will make note here that I am using raw push
notifications.
I understand that push channels will expire every so often but for me it's
occuring each time I back out of the app/page and therefore when
onNavigateTo is called I find the push channel which does exist and a new
channel uri is always created. Is this correct?
My code is as follows:
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);
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();
}
So to clarify, the app is opened and the push channel is registered and
the channel uri is saved in my web service. The web service then sends
notifications to the channel uri. When I exit the app or page and return
to it, the push channel is found but there a new channel uri is create
which is saved to my web service. My channels table in effect just keeps
growing and growing.
So is this the way it should work with new channel uri's continually
generated? It kind of doesn't make sense to me. I'm not sure how toast and
tile notifications work but I'd assume the channel uri needs to be static
when the app closes to keep receiving notifications while the app is
closed, but perhaps that could be a functionality of bindtotoast and
bindtotile and what I'm doing is correct because it's to do with raw
notifications.
No comments:
Post a Comment