以下代码在使用相机拍摄照片时效果很好,但是当用户点按视频时应用会崩溃。
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)
}
}
答案 0 :(得分:11)
我遇到了类似的问题,原因是我的Info.plist
没有要求麦克风使用权限。
检查您是否具有适当的值:
NSCameraUsageDescription
(Privacy - Camera Usage Description
)NSMicrophoneUsageDescription
(Privacy - Microphone Usage Description
)NSPhotoLibraryUsageDescription
(Privacy - Photo Library Usage Description
)然后当您从照片模式更改为视频模式时,您的应用会请求麦克风访问,而不仅仅是崩溃。