因此,我尝试使用Azure和Windows Phone 8进行推送通知,但我得到了一个不支持的频道uri:' http://s.notify ....' 例外。我们使用android和ios,但我的Windows手机有问题。所以在Windows手机上,首先打电话就像下面的代码一样。这给了我一个看起来像这样的Uri:
我获得此代码的方式是使用以下代码:
HttpNotificationChannel pushChannel;
// Try to find the push channel.
pushChannel = HttpNotificationChannel.Find(App.HubName);
// If the channel was not found, then create a new connection to the push service.
if (pushChannel == null)
{
pushChannel = new HttpNotificationChannel(App.HubName, App.ServiceName);
// 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);
// Register for this notification only if you need to receive the notifications while your application is running.
pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
pushChannel.Open();
// Bind this new channel for Tile events.
pushChannel.BindToShellToast();
}
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);
// Register for this notification only if you need to receive the notifications while your application is running.
pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
// Display the URI for testing purposes. Normally, the URI would be passed back to your web service at this point.
System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
MessageBox.Show(String.Format("Channel Uri is {0}", pushChannel.ChannelUri.ToString()));
}
之后,我将 pushChannel.ChannelUri 发送到服务器,以创建我的设备的后端注册。通话时出现错误(不支持的频道uri ):
var registrationDescription = await _hub.CreateOrUpdateRegistrationAsync(registration);
注册来自:
RegistrationDescription registration = new WindowsTemplateRegistrationDescription(request.Handle, request.Template);
Handle是我发送给服务器的请求,模板是xml模板。
现在我不知道出了什么问题,因为这个错误而变得有点疯狂。特别是因为代码适用于android和ios,但不适用于wp8。我还尝试使用 PushNotificationChannelManager ,但它只是在执行 CreatePushNotificationChannelForApplicationAsync 调用时崩溃。
提前致谢
答案 0 :(得分:0)
在WinPhone 8.0之前,该平台的推送通知由“MPNS”(Microsoft推送通知系统)完成。在Windows Phone 8.1上,现在有两个选项:如果您正在构建新的通用或“存储”版本,则使用与常规Windows应用商店应用相同的版本(WNS - Windows通知系统)。你正在做的是在同一代码中混合两个版本的通知。使用HttpPushNotification
类(来自Microsoft.Phone.Notification
命名空间)创建通知通道时,您正在使用MPNS注册。如果是这种情况,那么你不应该使用WindowsTemplateRegistrationDescription
类;相反,请使用MpnsTemplateRegistrationDescription
。
答案 1 :(得分:-1)
如果您在手机模拟器中运行代码: 模拟器不支持接收推送消息 - 您必须使用“真实”电话。