Reputation: 1885
After some magic transformations (I have really missed this moment in time) my application is now refusing to find an existing push channel by name. Run after run and after run HttpNotificationChannel.Find constantly returns null
The main mystery of this issue that my code (that listed below) was written roughly year ago and last time I've checked, was working fine.
My only assumption is that UnbindToShellToast was accidentally called and push channel was removed after app termination. I have double-checked everything and removed any single UnbindToShellToast call from my code and it still returns null every run.
So, what's my problem? Maybe that I'm developing for windows phone?
_httpChannel = HttpNotificationChannel.Find(ChannelName);
if (_httpChannel == null)
{
_httpChannel = new HttpNotificationChannel(ChannelName);
}
_channelUri = Observable.Create<string>(observer =>
{
if (_httpChannel != null && _httpChannel.ChannelUri != null && _httpChannel.ChannelUri.OriginalString.IsNotEmpty())
{
observer.OnNext(_httpChannel.ChannelUri.OriginalString);
}
else
{
observer.OnNext(string.Empty);
}
return Observable.FromEventPattern<NotificationChannelUriEventArgs>(_httpChannel, "ChannelUriUpdated")
.Select(i => i.EventArgs.ChannelUri.OriginalString).Subscribe(observer);
});
if (_httpChannel.ChannelUri == null)
{
try
{
_httpChannel.Open();
}
catch (Exception ex)
{
Debug.WriteLine("PushChannel Open failed: " + ex.Message);
}
}
if (!_httpChannel.IsShellToastBound)
{
try
{
_httpChannel.BindToShellToast();
}
catch (Exception ex)
{
Debug.WriteLine("PushChannel BindToShellToast failed: " + ex.Message);
}
}
This code was tested on Lumia 1520 (8.10.14234.375)
Upvotes: 1
Views: 143
Reputation: 1389
This is a known pattern in Windows Phone 8.1. Since it uses WNS behind the scenes instead of MPNS, you need to always ask for new channel uri whenever your app launches. If you run same code in Windows Phone 8.0, you'll get your expected behavior.
Upvotes: 2