在调用RegisterNativeAsync时,使用Xamarin的WindowsAzure.Messaging for iOS会产生ObjC运行时异常

问题描述 投票:3回答:2

我正在测试使用Azure Notifications Hubs在我的iOS设备上注册推送通知。

按照这里的教程:https://docs.microsoft.com/en-us/azure/notification-hubs/xamarin-notification-hubs-ios-push-notification-apns-get-started

调用Hub.RegisterNativeAsync(deviceToken, tags, (errorCallback) => {时出现运行时异常

特别是例外是:

ObjCRuntime.RuntimeException

链接动态注册器后,不支持BlockLiteral.SetupBlock。

堆栈跟踪:

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 

显然我在这里做错了。寻找任何建议,我可以在哪里找到纠正它。

azure xamarin.ios
2个回答
3
投票

似乎我的解决方案是:

  • 退出Visual Studio Mac
  • 重启Visual Studio Mac
  • 干净的项目
  • 再次构建和运行项目

现在它有效。


2
投票

退出/清理顺序对我不起作用。但是,我补充说,阅读一些微软的文档

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

到csproj,这解决了我的问题。

© www.soinside.com 2019 - 2024. All rights reserved.