iOS 11 application crashes when trying to add attachment from camera

118 Views Asked by At

I have an application that crashes when the user tries to add an attachment from the camera (however it doesn't crash when they opt to load the attachment from their Photo Library).

Here's the method that gets called when an option (either Camera or Photo Library) is selected:

    public void AddMedia(UIImagePickerControllerSourceType type)
    {
        _imagePicker = new UIImagePickerController();

        // set our source to the photo library
        _imagePicker.SourceType = type;

        // set what media types
        _imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes(type);

        _imagePicker.FinishedPickingMedia += Handle_FinishedPickingMedia;

        _imagePicker.Canceled += (sender, evt) =>
        {
            Console.WriteLine("picker cancelled");
            _imagePicker.DismissViewController(false, () =>
                {
                });
        };

        //PresentModalViewController is depreciated in iOS6 so we use PresentViewController
        Parent.PresentViewController(_imagePicker, true, null);
    }

And this is the line where it crashes:

        _imagePicker.SourceType = type;

Why would it crash when setting it to Camera but not Photo Library? Does it have something to do with how the enum is ordered (Photo Library = 0, Camera = 1, Saved Photos Album = 2)?

1

There are 1 best solutions below

1
On

Are you trying to reproduce it on simulator? Because you don't have an access to camera on it.