0

所以我试图让推送通知与Azure和Windows Phone 8一起工作,但我得到一个不受支持的频道uri:'http://s.notify ....'异常。我们得到它与Android和IOS的工作,但我有一个与Windows手机的问题。因此,在Windows Phone上首先进行呼叫就像下面的代码。这给了我一个开放的,看起来像这样:Windows Phone 8推送通知 - 不支持的频道uri

http://s.notify.live.net/u/1/db3/HmQAAABvGpd1XkjaC-XkYBpLYRrzC_DuH5ahcYzhdl8bT38ZJwNhI7_RGjG2ggirG0P1LJ2e6QAYm0uslRnGqcaImzdq/cHYtZGV2ZWxvcC1tZXNzYWdlcw/7A7WUjse3k2tlLMokVXD6g/rJ4ipeALhkNuxmeeJAAdsrrKRhY

我得到这个代码的方法是使用下面的代码:

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); 

手柄被乌里我发送到服务器的请求,并且该模板是XML模板。

现在我不知道出了什么问题,并且因为这个错误而变得有点疯狂。特别是因为代码适用于android和ios,但不适用于wp8。我也尝试过使用PushNotificationChannelManager,但它只是在执行CreatePushNotificationChannelForApplicationAsync调用时崩溃。

在此先感谢

回答

0

在WinPhone 8.0之前,该平台的推送通知由“MPNS”(Microsoft推送通知系统)完成。在Windows Phone 8.1上,现在有两种选择:如果要构建新的通用或“存储”版本,则应使用与常规Windows应用商店应用(WNS-Windows通知系统)相同的版本。你正在做的是在相同的代码中混合通知的两个版本。当您使用HttpPushNotification类(来自Microsoft.Phone.Notification名称空间)创建通知通道时,您正在使用MPNS注册。如果是这种情况,那么你不应该使用WindowsTemplateRegistrationDescription类;相反,使用MpnsTemplateRegistrationDescription之一。

+0

工作很好。非常感谢carlosfigueira !!!!! – kermmeer 2014-09-26 09:32:58

-1

如果您运行的代码,在手机模拟器: 模拟器不支持recieving Push信息 - 你将不得不使用一个“真正”的电话。

+0

嗨,谢谢你的提示。起初我使用模拟器。现在我在一个真实的设备上。但问题不在于接收,而在于我们自己的后端和天蓝色的通知中心之间的注册。 – kermmeer 2014-09-25 15:11:22

+1

这是不正确的 - Windows Phone模拟器能够接收推送通知。 – carlosfigueira 2014-09-25 16:28:07

+0

@carlosfigueira:奇怪 - 因为通过电话8.1不断告诉我,在每个程序开始 – fnupp 2014-09-25 17:00:30