简体   繁体   中英

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)
     }
 }

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM