Reputation: 1332
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
Reputation: 351
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