Fahad Rehman Fahad Rehman - 16 days ago 9
iOS Question

Can not Capture Video Using iOS Default Camera Application. Xamarin.iOS

I am trying to launch the default iOS camera application for video recording but it does not work.

Whenever I launch the application it crashes and and does not show any error log or any other error messages.

The following code works perfectly if I set the

imagePicker.CameraCaptureMode
to
UIImagePickerControllerCameraCaptureMode.Photo
.

var imagePicker = new UIImagePickerController();
imagePicker.SourceType = UIImagePickerControllerSourceType.Camera;
imagePicker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Video;
var imagePickerDelegate = new ImagePickerDelegate(this);
imagePicker.Delegate = imagePickerDelegate;
NavigationController.PresentModalViewController(imagePicker, true);


Thanks in advance

Answer

I got it to work by doing this:

var imagePicker = new UIImagePickerController();
imagePicker.SourceType = UIImagePickerControllerSourceType.Camera;
imagePicker.MediaTypes = new string[]{ UTType.Movie }; // ADD this
var imagePickerDelegate = new ImagePickerDelegate(this);
imagePicker.Delegate = imagePickerDelegate;
NavigationController.PresentModalViewController(imagePicker, true);

Also you can set your delegate calls like so:

    imagePicker.FinishedPickingMedia += Handle_FinishedPickingMedia;
    imagePicker.Canceled += Handle_Canceled;

Then create these methods:

    protected void Handle_FinishedPickingMedia(object sender, UIImagePickerMediaPickedEventArgs e)
    {
        //code to handle picking media
    }

    void Handle_Canceled(object sender, EventArgs e)
    {
        imagePicker.DismissViewController(true, null);
    }

Update

In iOS 10 you need to add the permissions and provide the description as to why you are asking for the permission in the info.plist

see here:

iOS 10 - Changes in asking permissions of Camera, microphone and Photo Library causing application to crash

Comments