Xamarin IOS ImagePicker在项目选择上崩溃

时间:2015-11-26 17:07:17

标签: ios xamarin uiimagepickercontroller

我有一个带ImagePicker的控制器。当在模拟器上选择图像时,一切正常,当它在设备上运行时我发生了可怕的崩溃!

如果我尝试调试,调试器不会在方法内停止,如果我写了一些东西来记录方法,它就不会被记录。

这是我的选择码:

imagePicker = new UIImagePickerController ();
            imagePicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary;
            imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes (UIImagePickerControllerSourceType.PhotoLibrary);
            imagePicker.FinishedPickingMedia += ImagePicker_FinishedPickingMedia;
            imagePicker.Canceled += (sender, e) => { imagePicker.DismissModalViewController (true);};
            profPic.UserInteractionEnabled = true;
            profPic.AddGestureRecognizer(new UITapGestureRecognizer(()=>
            {
                NavigationController.ShowViewController(imagePicker, this);
            }));

这是一个例外:

2015-11-26 17:54:41.933 FairbooksIOS[204:5289] critical: Stacktrace:

2015-11-26 17:54:41.934 FairbooksIOS[204:5289] critical:   at <unknown> <0xffffffff>
2015-11-26 17:54:41.934 FairbooksIOS[204:5289] critical:   at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <0xffffffff>
2015-11-26 17:54:41.935 FairbooksIOS[204:5289] critical:   at UIKit.UIApplication.Main (string[],intptr,intptr) [0x00005] in /Users/builder/data/lanes/2320/1f068b49/source/maccore/src/UIKit/UIApplication.cs:77
2015-11-26 17:54:41.935 FairbooksIOS[204:5289] critical:   at UIKit.UIApplication.Main (string[],string,string) [0x0001c] in /Users/builder/data/lanes/2320/1f068b49/source/maccore/src/UIKit/UIApplication.cs:60
2015-11-26 17:54:41.936 FairbooksIOS[204:5289] critical:   at Fairbooks.IOS.Application.Main (string[]) [0x00009] in /Users/ziba/git/Fairbooks.IOS/Main.cs:19
2015-11-26 17:54:41.936 FairbooksIOS[204:5289] critical:   at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0xffffffff>
2015-11-26 17:54:41.936 FairbooksIOS[204:5289] critical: 
Native stacktrace:

2015-11-26 17:54:42.090 FairbooksIOS[204:5289] critical:    0   FairbooksIOS                        0x0000000100cf9278 mono_handle_native_sigsegv + 260
2015-11-26 17:54:42.090 FairbooksIOS[204:5289] critical:    1   FairbooksIOS                        0x0000000100d061c4 mono_sigsegv_signal_handler + 328
2015-11-26 17:54:42.091 FairbooksIOS[204:5289] critical:    2   libsystem_platform.dylib            0x000000019a2bd94c _sigtramp + 68
2015-11-26 17:54:42.091 FairbooksIOS[204:5289] critical:    3   FairbooksIOS                        0x0000000100de9c24 _ZL16get_raw_gchandleP11objc_object + 44
2015-11-26 17:54:42.091 FairbooksIOS[204:5289] critical:    4   FairbooksIOS                        0x0000000100de9bc4 _ZL12get_gchandleP11objc_object + 24
2015-11-26 17:54:42.092 FairbooksIOS[204:5289] critical:    5   FairbooksIOS                        0x0000000100de9834 xamarin_get_gchandle + 24
2015-11-26 17:54:42.092 FairbooksIOS[204:5289] critical:    6   FairbooksIOS                        0x0000000100de9788 xamarin_get_nsobject_with_type_for_ptr_created + 100
2015-11-26 17:54:42.092 FairbooksIOS[204:5289] critical:    7   FairbooksIOS                        0x0000000100df38cc xamarin_trampoline + 4144
2015-11-26 17:54:42.092 FairbooksIOS[204:5289] critical:    8   UIKit                               0x000000018a77ef70 <redacted> + 168
2015-11-26 17:54:42.093 FairbooksIOS[204:5289] critical:    9   PhotoLibrary                        0x0000000192804ffc PLNotifyImagePickerOfImageAvailability + 80
2015-11-26 17:54:42.093 FairbooksIOS[204:5289] critical:    10  PhotosUI                            0x00000001897ec5f4 <redacted> + 168
2015-11-26 17:54:42.093 FairbooksIOS[204:5289] critical:    11  PhotosUI                            0x00000001897ec37c <redacted> + 44
2015-11-26 17:54:42.094 FairbooksIOS[204:5289] critical:    12  PhotosUI                            0x0000000189914ca4 <redacted> + 308
2015-11-26 17:54:42.094 FairbooksIOS[204:5289] critical:    13  PhotosUI                            0x0000000189914680 <redacted> + 96
2015-11-26 17:54:42.094 FairbooksIOS[204:5289] critical:    14  libdispatch.dylib                   0x000000019a0a16e8 <redacted> + 24
2015-11-26 17:54:42.094 FairbooksIOS[204:5289] critical:    15  libdispatch.dylib                   0x000000019a0a16a8 <redacted> + 16
2015-11-26 17:54:42.095 FairbooksIOS[204:5289] critical:    16  libdispatch.dylib                   0x000000019a0a6db0 _dispatch_main_queue_callback_4CF + 1844
2015-11-26 17:54:42.095 FairbooksIOS[204:5289] critical:    17  CoreFoundation                      0x0000000184cf81f8 <redacted> + 12
2015-11-26 17:54:42.095 FairbooksIOS[204:5289] critical:    18  CoreFoundation                      0x0000000184cf6060 <redacted> + 1628
2015-11-26 17:54:42.095 FairbooksIOS[204:5289] critical:    19  CoreFoundation                      0x0000000184c24ca0 CFRunLoopRunSpecific + 384
2015-11-26 17:54:42.095 FairbooksIOS[204:5289] critical:    20  GraphicsServices                    0x000000018fc8c088 GSEventRunModal + 180
2015-11-26 17:54:42.096 FairbooksIOS[204:5289] critical:    21  UIKit                               0x000000018a33cffc UIApplicationMain + 204
2015-11-26 17:54:42.096 FairbooksIOS[204:5289] critical:    22  FairbooksIOS                        0x000000010029c94c wrapper_managed_to_native_UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr + 348
2015-11-26 17:54:42.096 FairbooksIOS[204:5289] critical:    23  FairbooksIOS                        0x000000010021f1fc UIKit_UIApplication_Main_string___intptr_intptr + 44
2015-11-26 17:54:42.096 FairbooksIOS[204:5289] critical:    24  FairbooksIOS                        0x000000010021f1bc UIKit_UIApplication_Main_string___string_string + 172
2015-11-26 17:54:42.096 FairbooksIOS[204:5289] critical:    25  FairbooksIOS                        0x00000001000d1278 Fairbooks_IOS_Application_Main_string__ + 184
2015-11-26 17:54:42.097 FairbooksIOS[204:5289] critical:    26  FairbooksIOS                        0x00000001004a89c4 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 244
2015-11-26 17:54:42.097 FairbooksIOS[204:5289] critical:    27  FairbooksIOS                        0x0000000100d084a4 mono_jit_runtime_invoke + 1264
2015-11-26 17:54:42.097 FairbooksIOS[204:5289] critical:    28  FairbooksIOS                        0x0000000100d6c224 mono_runtime_invoke + 124
2015-11-26 17:54:42.097 FairbooksIOS[204:5289] critical:    29  FairbooksIOS                        0x0000000100d70aac mono_runtime_exec_main + 400
2015-11-26 17:54:42.097 FairbooksIOS[204:5289] critical:    30  FairbooksIOS                        0x0000000100e0149c xamarin_main + 1840
2015-11-26 17:54:42.098 FairbooksIOS[204:5289] critical:    31  FairbooksIOS                        0x0000000100bf6138 main + 96
2015-11-26 17:54:42.099 FairbooksIOS[204:5289] critical:    32  libdyld.dylib                       0x000000019a0d28b8 <redacted> + 4
2015-11-26 17:54:42.099 FairbooksIOS[204:5289] critical: 

1 个答案:

答案 0 :(得分:0)

这可能是因为您将imagePicker作为局部变量,并在用户选择图像之前由垃圾收集器收集。尝试将imagePicker保持在全局/类级别。如果问题仍然存在,请检查NavigationController的值(它可能为null)。如果有效,请告诉我!