Forum Xamarin Xamarin.iOS

Why is my UIImagePickerController crashing my app when I try to present it?

TrevorYokumTrevorYokum USMember ✭✭

Hey Xamarin.iOS, I'm having a pretty pesky problem that involves the UIImagePickerController that I don't understand. My application sometimes requires a picture to be taken when submitting a response to our server; I've set up my UIImagePickerController like so:

        UIImagePickerController picker = new UIImagePickerController();
        if(UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.Camera))
        {
            picker.SourceType = UIImagePickerControllerSourceType.Camera;
            picker.CameraDevice = UIImagePickerControllerCameraDevice.Rear;
        }
        picker.MediaTypes = UIImagePickerController.AvailableMediaTypes(UIImagePickerControllerSourceType.Camera);
        picker.ImagePickerControllerDelegate = new ImagePickerDelegate(this, picker);

And I present the view controller like so:

        button.TouchUpInside += (sender, e) =>
        {
            PresentViewController(picker, true, null);
        };

And my UIImagePickerControllerDelegate class looks like this:

class ImagePickerDelegate : UIImagePickerControllerDelegate
{
    public UIViewController parent;
    public UIImagePickerController picker;
    public ImagePickerDelegate(RouteController p, UIImagePickerController pick)
    {
        parent = p;
        picker = pick;
    }
    public override void FinishedPickingMedia(UIImagePickerController picker, NSDictionary info)
    {
        parent.DismissViewController(true, null);
    }
    public override void Canceled(UIImagePickerController picker)
    {
        parent.DismissViewController(true, null);
    }
    public override void FinishedPickingImage(UIImagePickerController picker, UIImage image, NSDictionary editingInfo)
    {
        parent.DismissViewController(true, null);
    }
}

You will notice that the UIViewController that I pass to the delegate is of type RouteController; however, that should not cause any problems because it is of type RouteController : UIViewController.

My app crashes as soon as I attempt to use PresentViewController(picker, true, null); I just do not understand, as I've implemented the Delegate object requested by the Apple documentation on the topic.

I get this stack trace when my app crashes:

`2017-05-05 16:22:42.505 LoginApp[3176:623259] critical:
Native stacktrace:
2017-05-05 16:22:42.587 LoginApp[3176:623259] critical: 0 LoginApp 0x0000000100129290 mono_handle_native_sigsegv + 256
2017-05-05 16:22:42.587 LoginApp[3176:623259] critical: 1 libsystem_platform.dylib 0x0000000189aef348 _sigtramp + 52
2017-05-05 16:22:42.588 LoginApp[3176:623259] critical: 2 libsystem_kernel.dylib 0x0000000189a29480 + 100
2017-05-05 16:22:42.588 LoginApp[3176:623259] critical: 3 libsystem_kernel.dylib 0x0000000189a294c8 system_set_sfi_window + 0
2017-05-05 16:22:42.588 LoginApp[3176:623259] critical: 4 TCC 0x000000018cc6a560 + 0
2017-05-05 16:22:42.588 LoginApp[3176:623259] critical: 5 TCC 0x000000018cc6a45c + 0
2017-05-05 16:22:42.588 LoginApp[3176:623259] critical: 6 TCC 0x000000018cc6d52c + 288
2017-05-05 16:22:42.588 LoginApp[3176:623259] critical: 7 libxpc.dylib 0x0000000189b3401c + 80
2017-05-05 16:22:42.589 LoginApp[3176:623259] critical: 8 libxpc.dylib
0x0000000189b33f8c + 40
2017-05-05 16:22:42.589 LoginApp[3176:623259] critical: 9 libdispatch.dylib 0x00000001898e91c0 + 16
2017-05-05 16:22:42.589 LoginApp[3176:623259] critical: 10 libdispatch.dylib 0x00000001898f7ab4 + 732
2017-05-05 16:22:42.589 LoginApp[3176:623259] critical: 11 libdispatch.dylib 0x00000001898f938c + 572
2017-05-05 16:22:42.589 LoginApp[3176:623259] critical: 12 libdispatch.dylib 0x00000001898f90ec + 124
2017-05-05 16:22:42.589 LoginApp[3176:623259] critical: 13 libsystem_pthread.dylib 0x0000000189af12c8 _pthread_wqthread + 1288
2017-05-05 16:22:42.590 LoginApp[3176:623259] critical: 14 libsystem_pthread.dylib 0x0000000189af0db4 start_wqthread + 4

2017-05-05 16:22:42.590 LoginApp[3176:623259] critical:

Got a SIGABRT while executing native code. This usual
ly indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================`

Do I need to set the Frame, or something? What am I missing here?

Any help would be greatly appreciated, as always. Thanks!

Sign In or Register to comment.