繁体   English   中英

Windows 8.1应用程序中的Toast通知

[英]Toast notification in windows 8.1 app

我面临一个奇怪的问题。 我使用Windows Phone 8.1 silverlightWindows通用链接进行Toast通知。 我能够在Windows Phone应用程序中获取Toast通知,它在链接中提到的Windows 8.1中几乎相同。 但是Toast并没有在Windows 8.1中出现。

步骤 : -

1 - >我已经从Package.appxmanifest文件中启用了Toast。

2 - >然后我在上面提到的on_launched事件中的App.Xaml.cs中添加了这段代码

它显示了注册成功,如链接中所述

private async void InitNotificationsAsync()
{
      var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
      var hub = new NotificationHub("<hub name>", "<connection string with listen access>");
      var result = await hub.RegisterNativeAsync(channel.Uri);

                // Displays the registration ID so you know it was successful
      if (result.RegistrationId != null)
      {
           var dialog = new MessageDialog("Registration successful: " + result.RegistrationId);
           dialog.Commands.Add(new UICommand("OK"));
       await dialog.ShowAsync();
      }
}

3 - >现在我从后端发送通知( Hub正在处理手机mpns通知的情况 )。

public static async void SendNotificationAsync()
{
        NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString("<connection string with full access>", "<hub name>");
        var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">Hello from a .NET App!</text></binding></visual></toast>";
        await hub.SendWindowsNativeNotificationAsync(toast);
 }

问题 : - 你们有一个线索,为什么它不能在Windows 8.1中工作或我缺少什么。 这是我正在经历的最简单的例子。 任何帮助表示赞赏。

编辑 : - 这是有趣的事情。

当我试图从azure门户网站发送通知时。 My-NotificationHub DEBUG选项卡到这里我选择WNS toast然后显示错误。

Error - The token obtained from the token provider is wrong

但是当我试图发送MPNS通知时,没有错误。 正如我已经提到的那样,它正在为WP 8.1 silverlight MPNS toast

What could be the cause of this error ?

如MSDN文档中所述,Toast无法在模拟器上运行:

注意通过Microsoft Visual Studio测试Toast通知代码功能时,必须在Windows x86,x64或Windows运行时计算机上使用本地计算机或远程计算机调试设置。 您不能使用Visual Studio Simulator调试功能选项 - 您的代码将在模拟器中编译和运行,但不会出现Toast。

资料来源: http//msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868254.aspx

如果我在Windows 8上正确记得,当我使用模拟器时,Toast通知不起作用。 我不得不在我的计算机上部署我的Windows 8应用程序而不是模拟器,以便能够看到吐司通知。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM