Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Xamarin's WindowsAzure.Messaging for iOS yields ObjC Runtime Exception when invoking RegisterNativeAsync

I am testing registering for push notifications on my iOS device using Azure Notifications Hubs.

Following the tutorial here: https://learn.microsoft.com/en-us/azure/notification-hubs/xamarin-notification-hubs-ios-push-notification-apns-get-started

I get a runtime exception when invoking Hub.RegisterNativeAsync(deviceToken, tags, (errorCallback) => {

Specifically the exception is:

ObjCRuntime.RuntimeException

BlockLiteral.SetupBlock is not supported when the dynamic registrar has been linked away.

Stack trace:

at ObjCRuntime.BlockLiteral.SetupBlock (System.Delegate trampoline, System.Delegate userDelegate, System.Boolean safe) [0x00002] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.14.0.14/src/Xamarin.iOS/ObjCRuntime/Blocks.cs:94 
at ObjCRuntime.BlockLiteral.SetupBlock (System.Delegate trampoline, System.Delegate userDelegate) [0x001ef] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.14.0.14/src/Xamarin.iOS/ObjCRuntime/Blocks.cs:205 
at WindowsAzure.Messaging.SBNotificationHub.RegisterNativeAsync (Foundation.NSData deviceToken, Foundation.NSSet tags, WindowsAzure.Messaging.ErrorCallback errorCallback) [0x0002d] in <c5112db82ee94ad88e9a597b356dac0c>:0 
at MyApp.Test.Azure.AzureNotificationHubService.OnRegisteredForRemoteNotifications (Foundation.NSData deviceToken) [0x00019] in /Users/aventurella/github/my-test-app/MyApp.Test.Azure/Services/AzureNotificationHubService.cs:47 
at MyApp.Test.Azure.AppDelegate.RegisteredForRemoteNotifications (UIKit.UIApplication application, Foundation.NSData deviceToken) [0x00001] in /Users/aventurella/github/my-test-app/MyApp.Test.Azure/AppDelegate.cs:47 
at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.14.0.14/src/Xamarin.iOS/UIKit/UIApplication.cs:79 
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0002c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.14.0.14/src/Xamarin.iOS/UIKit/UIApplication.cs:63 
at MyApp.Test.Azure.Application.Main (System.String[] args) [0x00001] in /Users/aventurella/github/my-test-app/MyApp.Test.Azure/Main.cs:12 

So clearly I'm doing something wrong here. Looking for any advice on where I can look to correct it.

like image 663
AJ Venturella Avatar asked Sep 08 '18 23:09

AJ Venturella


2 Answers

The quit/clean up sequence did not work for me. But reading some Microsoft doc, I added

<MtouchExtraArgs>--optimize=-blockliteral-setupblock</MtouchExtraArgs>

to the csproj and that solved the issue for me.

like image 102
Christian M. Avatar answered Nov 18 '22 18:11

Christian M.


Seems my solution was:

  • quit Visual Studio Mac
  • restart Visual Studio Mac
  • clean project
  • build and run project again

Now it works.

like image 44
AJ Venturella Avatar answered Nov 18 '22 19:11

AJ Venturella



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!