在Windows phone Silverlight 8.1上接收WNS推送通知

我有windows phone 8.1 silverlight应用程序,我希望使用新框架WNS接收Notfications。

我在package.appxmanifest: 并将其添加到移动服务中心。

为此,我删除了对MPNS使用的旧引用,并为WNS添加了以下内容:

使用Windows.UI.Notifications;

使用Windows.Networking.PushNotifications;

使用Windows.UI.StartScreen;

这导致了获得channelURI的新方法:

  public static PushNotificationChannel CurrentChannel { get; private set; } public async static Task UploadChannel() { bool newChannel = false; var channel = await Windows.Networking.PushNotifications.PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); var settings = Windows.Storage.ApplicationData.Current.LocalSettings.Values; object oldChannel; settings.TryGetValue("channelURI", out oldChannel); if ((oldChannel as PushNotificationChannel).Uri != CurrentChannel.Uri) { settings.Add("channelURI", CurrentChannel); newChannel = true; } try { await App.MobileService.GetPush().RegisterNativeAsync(channel.Uri); } catch (Exception exception) { CurrentChannel.Close(); HandleRegisterException(exception); } CurrentChannel.PushNotificationReceived += CurrentChannel_PushNotificationReceived; return newChannel; } private static void HandleRegisterException(Exception exception) { MessageBox.Show("error - retry pushchannel"); } 

另外,我根据微软更新信息删除了ID_CAP_PushNotification我没有收到频道我收到错误:

该应用程序没有云通知function。 (来自HRESULT的exception:0x803E0110)

解决方案搜索错误并找到此链接 ,这可以通过访问package.appxmanifest并启用Internet(客户端和服务器)来解决,如下面的答案中所述。

错误2然后, UploadChannel()函数应该工作。 但是,Register API调用await App.MobileService.GetPush().RegisterNativeAsync(channel.Uri); 导致服务器出错:

消息=’无法注册’mpns’平台。 收到错误:’不支持的频道uri:’ https : //db3.notify.windows.com 。 。 。 。

错误是有道理的,但我不知道如何解决它。

Ekstra在服务器上我可以使用URI订阅,并接收通知。 但不是客户端。 这应该是怎么回事?

在客户端:

理想情况下,要使用WNS,您应该从WMAppManifest.xml中删除对MPNS的所有引用,并将Windowsapp store提供的信息添加到您的package.appxmanifest中。

我知道您正在从WP8迁移到WP8.1。 所以在你的package.appxmanifest中,编辑代码使它看起来像这样:

   

注意: PhonePublisherId中的0是故意的。 我不明白为什么,但是当我没有提供这样的应用程序时,应用程序将无法运行。

您正在执行通道uri请求权限:

 PushNotificationChannel channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); string channelUri = channel.Uri; 

您还应该在Package.appxmanifest中设置Internet(客户端和服务器)function以进行检查。

要在客户端接收通知,您应截取收到的通知,如下所述: https : //msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709907.aspx

在服务器端:

出现错误“不支持的通道URI”,因为您使用MPNS方法处理Azure服务器中的URI。

请参阅此处了解使用WNS的正确方法: http : //azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-windows-universal-dotnet-get-started-push/

添加internetClientfunction应该可以解决此错误。

创建通知通道会导致WPN_E_CLOUD_INCAPABLE错误原因:您的应用尚未在其应用清单(package.appxmanifest)中声明Internetfunction。 修复:确保您的应用清单已声明Internetfunction。 在Visual Studio清单编辑器中,您将在“function”选项卡下找到此选项作为Internet(客户端)。

用于Azure Mobile的.NET客户端SDK目前不支持在Windows Phone 8.1 Silverlight应用程序中使用WNS。 您必须使用MPN或将项目更改为NON-silverlight项目类型。

参考(参见Elio的回复): https : //social.msdn.microsoft.com/Forums/azure/en-US/1aa29977-a26d-4054-89b2-c853cbd35c18/wns-for-windows-phone-silverlight-81-apps -with-azuremobile服务?论坛= azuremobile

我不确定他们是否会更新它以支持这一点,因为Silveright for 8.1主要是为了与现有应用程序进行向后兼容,并且没有多少人使用移动服务,因为它更新。

就我而言,在我的项目设置中选择ARM平台就可以了。 我在“任何CPU”。