c# - Xamarin.Mac - 发送通知

标签 c# azure xamarin notifications xamarin.mac

我正在尝试使用 Azure 通知中心和 Xamarin.Mac 发送推送通知。 我有这个错误,我不知道为什么。有人可以帮我解决这个问题吗?

错误:

System.TypeInitializationException: The type initializer for 'TimerManager' threw an exception. ---> System.EntryPointNotFoundException: CreateWaitableTimer

我的代码:

 private static async void SendNotificationAsync()
 {
     NotificationHubClient hub = NotificationHubClient
         .CreateClientFromConnectionString("<connection string>", "<hub name>");
     string toast = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
         "<wp:Notification xmlns:wp=\"WPNotification\">" +
           "<wp:Toast>" +
               "<wp:Text1>Content</wp:Text1>" +
           "</wp:Toast> " +
         "</wp:Notification>";
     await hub.SendMpnsNativeNotificationAsync(toast);
 }

最佳答案

该库中有几个区域是 Windows 桌面特定的,并且在 Mono、UWP、Win10 IoT 等上不可用。(像 CreateWaitableTimer 这样的项目是 native Windows 桌面 API 调用)。

Azure 有许多不同的客户端和库,最“便携”的是 REST api,发送 MPNS native 通知涉及执行 POST 到:

https://{namespace}.servicebus.windows.net/{NotificationHub}/messages/?api-version=2015-01

文档显示了所需的内容和标题:

关于c# - Xamarin.Mac - 发送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46105525/

相关文章:

c# - 编译器使用 Port.Write 的 char 重载而不是 byte

c# - 字典包含键并在一个函数中获取值

Azure Node Function w/Eventhub 输出绑定(bind)到动态路由 ADX 表

android - 是否有适用于 iOS 和 Android 的 Xamarin.Form MediaPlayer?

c# - 对具有重复值的数组进行线性搜索

Azure 自动缩放 - 我有哪些选项?

azure - 使用 mqtt 以编程方式在 Azure IoT-hub 上注册设备

c# - Xamarin.Forms DependencyService Get() 方法在 PCL 中返回 Null

c# - 如何在xamarin forms android中更改工具栏后退图标

c# - .NET BitmapSource 正在锁定文件