我正在尝试使用 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/