如何在 Xamarin iOS 应用程序中检查相机访问权限,避免 "fatal error in the mono runtime"?
How to check for camera access in a Xamarin iOS app, avoiding "fatal error in the mono runtime"?
我正在尝试在 Xamarin iOS 应用程序中使用相机。
第一步似乎是检查应用程序是否可以访问相机。但是我在执行此操作时在单声道运行时遇到致命错误。有什么想法吗?
以下是有关异常的更多详细信息:
在 Visual Studio (2015) 中,我创建了一个新的 "Blank App (iPhone)" 项目。
由于我拥有 iPhone 3GS,因此我在项目属性中切换到 armv7,并将 select iOS 6.1 作为部署目标。
构建应用程序,在 iPhone 上调试:mac 代理运行良好,空应用程序在我的 phone.
上启动
然后我转到 AppDelegate.FinishedLaunching(...) 并添加
AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video);
在返回 true 之前。
重建应用程序,调试... GetAuthorizationStatus(...) 抛出异常。这是它的堆栈跟踪:
2016-06-24 12:50:22.691 App2[491:907] +[AVCaptureDevice authorizationStatusForMediaType:]: unrecognized selector sent to class 0x3a49c070
2016-06-24 12:50:22.704 App2[491:907] critical: Stacktrace:
2016-06-24 12:50:22.708 App2[491:907] critical: at <0xffffffff>
2016-06-24 12:50:22.712 App2[491:907] critical: at <0xffffffff>
2016-06-24 12:50:22.715 App2[491:907] critical:
Native stacktrace:
2016-06-24 12:50:22.964 App2[491:907] critical: 0 App2 0x0004f49d mono_handle_native_sigsegv + 240
2016-06-24 12:50:22.968 App2[491:907] critical: 1 App2 0x00056a23 mono_sigsegv_signal_handler + 222
2016-06-24 12:50:22.971 App2[491:907] critical: 2 libsystem_c.dylib 0x3a37ee93 _sigtramp + 42
2016-06-24 12:50:22.975 App2[491:907] critical: 3 App2 0x0033d3d0 map_dwarf_reg_to_hw_reg + 0
2016-06-24 12:50:22.978 App2[491:907] critical: 4 App2 0x0004ed4f mono_handle_exception_internal + 1508
2016-06-24 12:50:22.982 App2[491:907] critical: 5 App2 0x0004e767 mono_handle_exception + 30
2016-06-24 12:50:22.985 App2[491:907] critical: 6 App2 0x0004819b mono_arm_throw_exception + 106
2016-06-24 12:50:22.989 App2[491:907] critical: 7 App2 0x00244194 throw_exception + 64
2016-06-24 12:50:22.996 App2[491:907] critical: 8 App2 0x00274c74 ObjCRuntime_Runtime_throw_ns_exception_intptr + 28
2016-06-24 12:50:23.000 App2[491:907] critical: 9 App2 0x002ab490 wrapper_native_to_managed_ObjCRuntime_Runtime_throw_ns_exception_intptr + 72
2016-06-24 12:50:23.004 App2[491:907] critical: 10 App2 0x000f1bac xamarin_throw_ns_exception + 52
2016-06-24 12:50:23.007 App2[491:907] critical: 11 App2 0x000f3a64 _ZL17exception_handlerP11NSException + 224
2016-06-24 12:50:23.011 App2[491:907] critical: 12 CoreFoundation 0x322a457f + 614
2016-06-24 12:50:23.014 App2[491:907] critical: 13 libobjc.A.dylib 0x39f00a65 + 128
2016-06-24 12:50:23.018 App2[491:907] critical: 14 libc++abi.dylib 0x3994d07b + 78
2016-06-24 12:50:23.025 App2[491:907] critical: 15 libc++abi.dylib 0x3994d114 + 19
2016-06-24 12:50:23.029 App2[491:907] critical: 16 libc++abi.dylib 0x3994e599 cxa_current_exception_type + 0
2016-06-24 12:50:23.032 App2[491:907] critical: 17 libobjc.A.dylib 0x39f009d1 objc_exception_rethrow + 12
2016-06-24 12:50:23.036 App2[491:907] critical: 18 CoreFoundation 0x321eaf21 CFRunLoopRunSpecific + 456
2016-06-24 12:50:23.039 App2[491:907] critical: 19 CoreFoundation 0x321ead49 CFRunLoopRunInMode + 104
2016-06-24 12:50:23.043 App2[491:907] critical: 20 UIKit 0x34103485 + 668
2016-06-24 12:50:23.046 App2[491:907] critical: 21 UIKit 0x34100301 UIApplicationMain + 1120
2016-06-24 12:50:23.054 App2[491:907] critical: 22 App2 0x002a6fec wrapper_managed_to_native_UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr + 252
2016-06-24 12:50:23.057 App2[491:907] critical: 23 App2 0x0026f8a4 UIKit_UIApplication_Main_string___intptr_intptr + 52
2016-06-24 12:50:23.064 App2[491:907] critical: 24 App2 0x0026f864 UIKit_UIApplication_Main_string___string_string + 204
2016-06-24 12:50:23.069 App2[491:907] critical: 25 App2 0x0010a8e8 App2_Application_Main_string + 152
2016-06-24 12:50:23.073 App2[491:907] critical: 26 App2 0x00223870 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 256
2016-06-24 12:50:23.078 App2[491:907] critical: 27 App2 0x0005842b mono_jit_runtime_invoke + 1562
2016-06-24 12:50:23.083 App2[491:907] critical: 28 App2 0x000991e7 mono_runtime_invoke + 102
2016-06-24 12:50:23.087 App2[491:907] critical: 29 App2 0x0009c799 mono_runtime_exec_main + 284
2016-06-24 12:50:23.092 App2[491:907] critical: 30 App2 0x0010a4c0 xamarin_main + 2232
2016-06-24 12:50:23.096 App2[491:907] critical: 31 App2 0x002b6d6d main + 112
2016-06-24 12:50:23.101 App2[491:907] critical: 32 libdyld.dylib 0x3a337b20 + 0
2016-06-24 12:50:23.106 App2[491:907] 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.
+[AVCaptureDevice authorizationStatusForMediaType:]: unrecognized selector sent to class 0x3a49c070
您设备上 iOS 运行 的版本是多少?
select iOS 6.1 as deployment target.
因为如果它是 6.1,就像您的部署目标一样,那么您不能调用它 API,因为它是在 iOS 7.0 中添加的。
您需要在 iOS 7.0+ 上有条件地调用它,例如
if (UIDevice.CurrentDevice.CheckSystemVersion (7,0)) {
AVCaptureDevice.GetAuthorizationStatus (AVMediaType.Video);
}
程序集浏览器可以通过属性向您显示 API 所需的最低版本。
我正在尝试在 Xamarin iOS 应用程序中使用相机。 第一步似乎是检查应用程序是否可以访问相机。但是我在执行此操作时在单声道运行时遇到致命错误。有什么想法吗?
以下是有关异常的更多详细信息:
在 Visual Studio (2015) 中,我创建了一个新的 "Blank App (iPhone)" 项目。 由于我拥有 iPhone 3GS,因此我在项目属性中切换到 armv7,并将 select iOS 6.1 作为部署目标。
构建应用程序,在 iPhone 上调试:mac 代理运行良好,空应用程序在我的 phone.
上启动然后我转到 AppDelegate.FinishedLaunching(...) 并添加 AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video); 在返回 true 之前。
重建应用程序,调试... GetAuthorizationStatus(...) 抛出异常。这是它的堆栈跟踪:
2016-06-24 12:50:22.691 App2[491:907] +[AVCaptureDevice authorizationStatusForMediaType:]: unrecognized selector sent to class 0x3a49c070
2016-06-24 12:50:22.704 App2[491:907] critical: Stacktrace:
2016-06-24 12:50:22.708 App2[491:907] critical: at <0xffffffff>
2016-06-24 12:50:22.712 App2[491:907] critical: at <0xffffffff>
2016-06-24 12:50:22.715 App2[491:907] critical:
Native stacktrace:
2016-06-24 12:50:22.964 App2[491:907] critical: 0 App2 0x0004f49d mono_handle_native_sigsegv + 240
2016-06-24 12:50:22.968 App2[491:907] critical: 1 App2 0x00056a23 mono_sigsegv_signal_handler + 222
2016-06-24 12:50:22.971 App2[491:907] critical: 2 libsystem_c.dylib 0x3a37ee93 _sigtramp + 42
2016-06-24 12:50:22.975 App2[491:907] critical: 3 App2 0x0033d3d0 map_dwarf_reg_to_hw_reg + 0
2016-06-24 12:50:22.978 App2[491:907] critical: 4 App2 0x0004ed4f mono_handle_exception_internal + 1508
2016-06-24 12:50:22.982 App2[491:907] critical: 5 App2 0x0004e767 mono_handle_exception + 30
2016-06-24 12:50:22.985 App2[491:907] critical: 6 App2 0x0004819b mono_arm_throw_exception + 106
2016-06-24 12:50:22.989 App2[491:907] critical: 7 App2 0x00244194 throw_exception + 64
2016-06-24 12:50:22.996 App2[491:907] critical: 8 App2 0x00274c74 ObjCRuntime_Runtime_throw_ns_exception_intptr + 28
2016-06-24 12:50:23.000 App2[491:907] critical: 9 App2 0x002ab490 wrapper_native_to_managed_ObjCRuntime_Runtime_throw_ns_exception_intptr + 72
2016-06-24 12:50:23.004 App2[491:907] critical: 10 App2 0x000f1bac xamarin_throw_ns_exception + 52
2016-06-24 12:50:23.007 App2[491:907] critical: 11 App2 0x000f3a64 _ZL17exception_handlerP11NSException + 224
2016-06-24 12:50:23.011 App2[491:907] critical: 12 CoreFoundation 0x322a457f + 614
2016-06-24 12:50:23.014 App2[491:907] critical: 13 libobjc.A.dylib 0x39f00a65 + 128
2016-06-24 12:50:23.018 App2[491:907] critical: 14 libc++abi.dylib 0x3994d07b + 78
2016-06-24 12:50:23.025 App2[491:907] critical: 15 libc++abi.dylib 0x3994d114 + 19
2016-06-24 12:50:23.029 App2[491:907] critical: 16 libc++abi.dylib 0x3994e599 cxa_current_exception_type + 0
2016-06-24 12:50:23.032 App2[491:907] critical: 17 libobjc.A.dylib 0x39f009d1 objc_exception_rethrow + 12
2016-06-24 12:50:23.036 App2[491:907] critical: 18 CoreFoundation 0x321eaf21 CFRunLoopRunSpecific + 456
2016-06-24 12:50:23.039 App2[491:907] critical: 19 CoreFoundation 0x321ead49 CFRunLoopRunInMode + 104
2016-06-24 12:50:23.043 App2[491:907] critical: 20 UIKit 0x34103485 + 668
2016-06-24 12:50:23.046 App2[491:907] critical: 21 UIKit 0x34100301 UIApplicationMain + 1120
2016-06-24 12:50:23.054 App2[491:907] critical: 22 App2 0x002a6fec wrapper_managed_to_native_UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr + 252
2016-06-24 12:50:23.057 App2[491:907] critical: 23 App2 0x0026f8a4 UIKit_UIApplication_Main_string___intptr_intptr + 52
2016-06-24 12:50:23.064 App2[491:907] critical: 24 App2 0x0026f864 UIKit_UIApplication_Main_string___string_string + 204
2016-06-24 12:50:23.069 App2[491:907] critical: 25 App2 0x0010a8e8 App2_Application_Main_string + 152
2016-06-24 12:50:23.073 App2[491:907] critical: 26 App2 0x00223870 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 256
2016-06-24 12:50:23.078 App2[491:907] critical: 27 App2 0x0005842b mono_jit_runtime_invoke + 1562
2016-06-24 12:50:23.083 App2[491:907] critical: 28 App2 0x000991e7 mono_runtime_invoke + 102
2016-06-24 12:50:23.087 App2[491:907] critical: 29 App2 0x0009c799 mono_runtime_exec_main + 284
2016-06-24 12:50:23.092 App2[491:907] critical: 30 App2 0x0010a4c0 xamarin_main + 2232
2016-06-24 12:50:23.096 App2[491:907] critical: 31 App2 0x002b6d6d main + 112
2016-06-24 12:50:23.101 App2[491:907] critical: 32 libdyld.dylib 0x3a337b20 + 0
2016-06-24 12:50:23.106 App2[491:907] 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.
+[AVCaptureDevice authorizationStatusForMediaType:]: unrecognized selector sent to class 0x3a49c070
您设备上 iOS 运行 的版本是多少?
select iOS 6.1 as deployment target.
因为如果它是 6.1,就像您的部署目标一样,那么您不能调用它 API,因为它是在 iOS 7.0 中添加的。
您需要在 iOS 7.0+ 上有条件地调用它,例如
if (UIDevice.CurrentDevice.CheckSystemVersion (7,0)) {
AVCaptureDevice.GetAuthorizationStatus (AVMediaType.Video);
}
程序集浏览器可以通过属性向您显示 API 所需的最低版本。