iOS将目标C块绑定到C#代码
我正在为以下目标C代码开发一个Xamarin.iOS绑定iOS将目标C块绑定到C#代码,c#,ios,objective-c,xamarin,xamarin.ios,C#,Ios,Objective C,Xamarin,Xamarin.ios,我正在为以下目标C代码开发一个Xamarin.iOS绑定 @interface Logger : NSObject + (void)setLogBlock:(void (^)(NSString* message, void* argument))logBlock; @end 到目前为止,我有以下代码: // @interface Logger : NSObject [BaseType(typeof(NSObject))] public partial interface Logger {
@interface Logger : NSObject
+ (void)setLogBlock:(void (^)(NSString* message, void* argument))logBlock;
@end
到目前为止,我有以下代码:
// @interface Logger : NSObject
[BaseType(typeof(NSObject))]
public partial interface Logger
{
// +(void)setLogBlock:(void (^)(NSString *, void *))logBlock;
[Static]
[Export("setLogBlock:")]
void SetLogBlock(LogDelegate logBlock);
}
// This declares the callback signature for the block:
public delegate void LogDelegate(NSString message, IntPtr arg);
这可以很好地编译,但当我开始在iOS模拟器上使用它时,应用程序崩溃,出现以下崩溃:
2016-06-24 16:47:01.047 BindingTest[26019:1633387] critical:
Native stacktrace:
2016-06-24 16:47:01.055 BindingTest[26019:1633387] critical: 0 libmonosgen-2.0.dylib 0x09cf2f4d mono_handle_native_sigsegv + 317
2016-06-24 16:47:01.055 BindingTest[26019:1633387] critical: 1 libmonosgen-2.0.dylib 0x09c419f6 mono_sigsegv_signal_handler + 214
2016-06-24 16:47:01.055 BindingTest[26019:1633387] critical: 2 libsystem_platform.dylib 0x0c3ef79b _sigtramp + 43
2016-06-24 16:47:01.055 BindingTest[26019:1633387] critical: 3 ??? 0xffffffff 0x0 + 4294967295
2016-06-24 16:47:01.055 BindingTest[26019:1633387] critical: 4 libdispatch.dylib 0x0c099456 dispatch_async + 342
2016-06-24 16:47:01.056 BindingTest[26019:1633387] critical: 5 BindingTest 0x00069ba3 otk_objc_log + 276
2016-06-24 16:47:01.056 BindingTest[26019:1633387] critical: 6 BindingTest 0x00537207 otk_console_append + 295
2016-06-24 16:47:01.056 BindingTest[26019:1633387] critical: 7 BindingTest 0x005385bb otk_ev_timer_callback + 155
2016-06-24 16:47:01.056 BindingTest[26019:1633387] critical: 8 BindingTest 0x0050ef4f uv__run_timers + 159
2016-06-24 16:47:01.056 BindingTest[26019:1633387] critical: 9 BindingTest 0x004fcba8 uv_run + 120
2016-06-24 16:47:01.056 BindingTest[26019:1633387] critical: 10 BindingTest 0x00538f74 otk_ev_thread_main + 148
2016-06-24 16:47:01.056 BindingTest[26019:1633387] critical: 11 BindingTest 0x00065f78 otkit_session_start_thread + 21
2016-06-24 16:47:01.057 BindingTest[26019:1633387] critical: 12 libsystem_pthread.dylib 0x0c3dc780 _pthread_body + 138
2016-06-24 16:47:01.057 BindingTest[26019:1633387] critical: 13 libsystem_pthread.dylib 0x0c3dc6f6 _pthread_body + 0
2016-06-24 16:47:01.057 BindingTest[26019:1633387] critical: 14 libsystem_pthread.dylib 0x0c3d9f7a thread_start + 34
2016-06-24 16:47:01.057 BindingTest[26019:1633387] critical:
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
iOS设备崩溃,堆栈跟踪如下:
Jun 24 19:11:26 am-6s Test[4795] <Warning>: ------------------------------------------------
Jun 24 19:11:29 am-6s Test[4795] <Warning>: critical: Stacktrace:
Jun 24 19:11:29 am-6s Test[4795] <Warning>: critical: at <unknown> <0xffffffff>
Jun 24 19:11:29 am-6s Test[4795] <Warning>: critical: at (wrapper managed-to-native) System.Runtime.InteropServices.GCHandle.CheckCurrentDomain (int) <0x00007>
Jun 24 19:11:29 am-6s Test[4795] <Warning>: critical: at System.Runtime.InteropServices.GCHandle.op_Explicit (intptr) [0x0001b] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Runtime.InteropServices/GCHandle.cs:124
Jun 24 19:11:29 am-6s Test[4795] <Warning>: critical: at System.Runtime.InteropServices.GCHandle.FromIntPtr (intptr) [0x00000] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Runtime.InteropServices/GCHandle.cs:166
Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: at ObjCRuntime.BlockLiteral.get_Target () [0x00015] in /Users/builder/data/lanes/3339/39ebb778/source/maccore/src/ObjCRuntime/Blocks.cs:126
Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: at ObjCRuntime.Trampolines/SDOpenTokLogBlockDelegate.Invoke (intptr,intptr,intptr) [0x00009] in ....iOS/obj/Debug/ios/ObjCRuntime/Trampolines.g.cs:60
Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: at (wrapper native-to-managed) ObjCRuntime.Trampolines/SDOpenTokLogBlockDelegate.Invoke (intptr,intptr,intptr) <0x000a7>
Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical:
Native stacktrace:
Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 0 libmonosgen-2.0.dylib 0x00000001008fe438 mono_handle_native_sigsegv + 260
Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 1 libmonosgen-2.0.dylib 0x0000000100909074 mono_sigsegv_signal_handler + 336
Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 2 libsystem_platform.dylib 0x00000001830d994c _sigtramp + 68
Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 3 libmonosgen-2.0.dylib 0x0000000100991334 mono_gchandle_is_in_domain + 20
Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 4 libmonosgen-2.0.dylib 0x000000010093e174 mono_gc_GCHandle_CheckCurrentDomain + 32
Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 5 libmscorlib.dll.dylib 0x0000000100ef1ec0 wrapper_managed_to_native_System_Runtime_InteropServices_GCHandle_CheckCurrentDomain_int + 96
Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 6 libmscorlib.dll.dylib 0x0000000100ef1de8 System_Runtime_InteropServices_GCHandle_op_Explicit_intptr + 56
Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 7 libmscorlib.dll.dylib 0x0000000100ef22fc System_Runtime_InteropServices_GCHandle_FromIntPtr_intptr + 28
Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 8 libXamarin.iOS.dll.dylib 0x0000000100c92b8c ObjCRuntime_BlockLiteral_get_Target + 76
Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 9 libOpenTok.iOS.dll.dylib 0x00000001020a05bc ObjCRuntime_Trampolines_SDOpenTokLogBlockDelegate_Invoke_intptr_intptr_intptr + 236
Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 10 libOpenTok.iOS.dll.dylib 0x00000001020b07f8 wrapper_native_to_managed_ObjCRuntime_Trampolines_SDOpenTokLogBlockDelegate_Invoke_intptr_intptr_intptr + 168
Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 11 libOpenTok.iOS.dll.dylib 0x0000000101b38428 __otk_objc_log_block_invoke6 + 48
Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 12 libdispatch.dylib 0x0000000182ec54bc <redacted> + 24
Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 13 libdispatch.dylib 0x0000000182ec547c <redacted> + 16
Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 14 libdispatch.dylib 0x0000000182ed14c0 <redacted> + 864
Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 15 libdispatch.dylib 0x0000000182ec8f80 <redacted> + 464
Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 16 libdispatch.dylib 0x0000000182ed3390 <redacted> + 728
Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 17 libdispatch.dylib 0x0000000182ed30b0 <redacted> + 112
Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 18 libsystem_pthread.dylib 0x00000001830dd470 _pthread_wqthread + 1092
Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical: 19 libsystem_pthread.dylib 0x00000001830dd020 start_wqthread + 4
Jun 24 19:11:30 am-6s Test[4795] <Warning>: critical:
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
Jun 24 19:11:26 am-6s测试[4795]:------------------------------------------------
6月24日19:11:29 am-6s测试[4795]:关键:Stacktrace:
6月24日19:11:29 am-6s试验[4795]:临界:在
6月24日19:11:29 am-6s测试[4795]:关键:at(包装器管理为本机)System.Runtime.InteropServices.GCHandle.CheckCurrentDomain(int)
6月24日19:11:29 am-6s测试[4795]:关键:在/Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Runtime.InteropServices/GCHandle.cs:124中显示(intptr)[0001b]
6月24日19:11:29 am-6s测试[4795]:关键:在/Users/builder/data/lanes/3339/39ebb778/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Runtime.InteropServices/GCHandle.cs:166
6月24日19:11:30 am-6s测试[4795]:关键:在/Users/builder/data/lanes/3339/39ebb778/source/maccore/src/ObjCRuntime/Blocks.cs:126中的ObjCRuntime.BlockLiteral.get_Target()[0x00015]
6月24日19:11:30 am-6s测试[4795]:关键:在ObjCRuntime.Trampolines/SDOpenTokLogBlockDelegate.Invoke(intptr,intptr,intptr)[0x00009]中…iOS/obj/Debug/iOS/ObjCRuntime/Trampolines.g.cs:60
6月24日19:11:30 am-6s测试[4795]:关键:at(包装器本机到托管)ObjCRuntime.Trampolines/SDOpenTokLogBlockDelegate.Invoke(intptr、intptr、intptr)
6月24日19:11:30 am-6s试验[4795]:关键:
本机堆栈跟踪:
6月24日19:11:30 am-6s测试[4795]:临界:0 libmonosgen-2.0.dylib 0x00000001008fe438 mono\u handle\u native\u sigsegv+260
6月24日19:11:30 am-6s测试[4795]:关键:1 libmonosgen-2.0.dylib 0x00000001009074 mono_-sigsegv_信号处理器+336
6月24日19:11:30 am-6s测试[4795]:关键:2 libsystem_platform.dylib 0x00000001830d994c_sigtramp+68
6月24日19:11:30 am-6s测试[4795]:关键:3 libmonosgen-2.0.dylib 0x0000000100991334 mono\u gchandle\u在\u域+20中
6月24日19:11:30 am-6s测试[4795]:关键:4 libmonosgen-2.0.dylib 0x000000010093e174 mono\u gc\u GCHandle\u CheckCurrentDomain+32
6月24日19:11:30 am-6s测试[4795]:关键:5 libmscorlib.dll.dylib 0x0000000100ef1ec0包装器\u托管\u本地\u系统\u运行时\u互操作服务\u GCHandle\u CheckCurrentDomain\u int+96
6月24日19:11:30 am-6s测试[4795]:关键:6 libmscorlib.dll.dylib 0x0000000100ef1de8系统运行时互操作服务GCHandle操作显式intptr+56
6月24日19:11:30 am-6s测试[4795]:关键:7 libmscorlib.dll.dylib 0x0000000100ef22fc系统\u运行时\u互操作服务\u GCHandle\u intptr\u intptr+28
6月24日19:11:30 am-6s测试[4795]:关键:8 libXamarin.iOS.dll.dylib 0x0000000100c92b8c ObjCRuntime\u BlockLiteral\u get\u Target+76
6月24日19:11:30 am-6s测试[4795]:关键:9 libOpenTok.iOS.dll.dylib 0x00000001020a05bc对象运行时\u蹦床\u SDOpenTokLogBlockDelegate\u调用\u intptr\u intptr\u intptr+236
6月24日19:11:30 am-6s测试[4795]:关键:10 libOpenTok.iOS.dll.dylib 0x00000001020b07f8包装器\u native\u to\u managed\u ObjCRuntime\u Trampolines\u SDOpenTokLogBlockDelegate\u Invoke\u intptr\u intptr+168
6月24日19:11:30 am-6s测试[4795]:关键:11 libOpenTok.iOS.dll.dylib 0x0000000101b38428_uuuotk_uobjc_log_block_uinvoke6+48
6月24日19:11:30 am-6s测试[4795]:关键:12 libdispatch.dylib 0x0000000182ec54bc+24
6月24日19:11:30 am-6s测试[4795]:关键:13 libdispatch.dylib 0x0000000182ec547c+16
6月24日19:11:30 am-6s测试[4795]:关键:14 libdispatch.dylib 0x0000000182ed14c0+864
6月24日19:11:30 am-6s测试[4795]:关键:15 libdispatch.dylib 0x0000000182ec8f80+464
6月24日19:11:30 am-6s测试[4795]:关键:16 libdispatch.dylib 0x0000000182ed3390+728
6月24日19:11:30 am-6s测试[4795]:关键:17 libdispatch.dylib 0x0000000182ed30b0+112
6月24日19:11:30 am-6s测试[4795]:严重:18 libsystem_pthread.dylib 0x00000001830dd470_pthread_wqthread+1092
6月24日19:11:30 am-6s测试[4795]:严重:19 libsystem_pthread.dylib 0x00000001830dd020 start_wqthread+4
6月24日19:11:30 am-6s试验[4795]:关键:
=================================================================
在执行本机代码时收到SIGSEGV。这通常表明
mono运行时或某个本机库中出现致命错误
由您的应用程序使用。
=================================================================
请告知。您在哪里执行?绑定中使用的库是否为fat静态库(包含您要支持的所有CPU体系结构)?@Sven MichaelStübe iOS模拟器,为设备编译会产生以下错误:MTOUCH:error MT3001:无法AOT程序集
iOSBinding.dll
是否已将库的x86/x64版本链接到绑定?是,所有Arch都在。请将当前绑定项目和示例添加到您的帖子中。将您的LinkWith.cs
、ApiDefinition.cs
和StructsAndEnums.cs
包含在帖子中也会很有好处。(或者只是上传绑定项目)在哪里执行?绑定中使用的库是否为fat静态库(包含