Anto Binish Kaspar
Anto Binish Kaspar

Reputation: 1332

UIImagePickerController crashes when video button is tapped

Following code works good when capturing photo using camera, but app crashes when user taps on video.

 let imagePicker = UIImagePickerController()
 imagePicker.modalPresentationStyle = .currentContext
 imagePicker.delegate = self
 if let _ = UIImagePickerController.availableMediaTypes(for: .camera) {
     imagePicker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .camera)!
     if UIImagePickerController.isSourceTypeAvailable(.camera) {
         imagePicker.sourceType = .camera
         present(imagePicker, animated: true, completion: nil)
     }
 }

Upvotes: 3

Views: 2061

Answers (1)

I had a similar problem and it was due to not asking for microphone usage permission in my Info.plist.

Check that you have a proper value for:

  • NSCameraUsageDescription (Privacy - Camera Usage Description)
  • NSMicrophoneUsageDescription (Privacy - Microphone Usage Description)
  • NSPhotoLibraryUsageDescription (Privacy - Photo Library Usage Description)

Then when you change from photo mode to video mode your app will ask for microphone access instead of just crashing.

Upvotes: 14

Related Questions