4

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

Iain Smith
  • 9,230
  • 4
  • 50
  • 61
Fahad Rehman
  • 1,189
  • 11
  • 25

1 Answers1

4

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

Community
  • 1
  • 1
Iain Smith
  • 9,230
  • 4
  • 50
  • 61
  • I've followed this, however the camera still crashes when in video mode. The camera will successfully launch into photo mode if `new string[]{ UTType.Image, UTType.Movie }` is used, but as soon as you switch to video mode even within the camera, the app crashes. Any help you can provide would be greatly appreciated. – Pithlit Nov 17 '16 at 20:05
  • 1
    you need to implement the permission for the microphone add the permissions string in info.plist refer to this http://stackoverflow.com/questions/38498275/ios-10-changes-in-asking-permissions-of-camera-microphone-and-photo-library-c if you still have any problem comment or ask new question and post your code. – Fahad Rehman Nov 18 '16 at 07:29
  • @FahadRehman cool thanks for catching that I'll update my answer. – Iain Smith Nov 18 '16 at 08:56