c# - Windows 8.1 应用程序中的 Toast 通知

标签 c# azure windows-phone-8 windows-8 windows-8.1

我遇到了一个奇怪的问题。我正在使用Windows phone 8.1 silverlightWindows universal Toast 通知的链接。我能够在 Windows Phone 应用程序中获取 toast 通知,这与链接中提到的 Windows 8.1 中的方式几乎相同。但 Windows 8.1 部分中并未出现 Toast。

步骤:-

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

2 -> 然后我在 App.Xaml.cs 的 on_launched 事件中添加了这段代码,如上所述

链接中显示注册成功

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 -> 现在我从后端发送通知(集线器在手机 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-NotificationHubDEBUG 选项卡中,我选择 WNS toast,然后它显示错误。

错误 - 从 token 提供者获取的 token 错误

但是当我尝试发送 MPNS 通知时,没有错误。正如我已经提到的,它适用于 WP 8.1 silverlight MPNS toast

此错误的原因可能是什么?

最佳答案

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

Note When testing toast notification code functionality through Microsoft Visual Studio, you must use either the Local Machine or Remote Machine debug setting on a Windows x86, x64, or Windows Runtime machine. You cannot use the Visual Studio Simulator debug function option—your code will compile and run in the Simulator, but the toast will not appear.

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

关于c# - Windows 8.1 应用程序中的 Toast 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24959396/

相关文章:

c# - 带有 HtmlAgilityPack 的 HTML Linq,或 P​​CL 中的替代方案

c# - 在页面/主页面和子页面之间共享相同的 View 模型

C# 4.0 动态对象和 WinAPI 接口(interface),如 IShellItem(无需在 C# 源代码中定义它们)

c# - AWS Lambda C# 上传对象到 S3

c# - Windows 桌面应用程序的想法

azure - 如何使用同一组标签为不同的文档布局训练自定义模型?

sql-server - 在 SQL 数据仓库中创建/选择外部表时处理嵌入的新行

c# - LINQ to Entities 无法识别自定义方法

azure - 屏蔽 Azure 存储库中文件内的数据

c# - 推送通知在 Windows Phone 8 中不起作用