简体   繁体   中英

Xamarin.Mac - Send notification

I'm trying to send push notification with Azure Notification Hub and Xamarin.Mac. I have this error, and I don't know why. Someone can help me to deal with it ?

The error:

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

My code:

 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);
 }

There are several areas of that library that are Windows Desktop specific and are not available on Mono, UWP, Win10 IoT, etc.. (Items like CreateWaitableTimer are native Windows Desktop API calls).

Azure has a number of different clients and libraries, the most "portable" is the REST api, sending a MPNS Native Notification involves performing a POST to:

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

The docs show the content and headers required:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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