点击视频按钮时UIImagePickerController崩溃

时间:2016-11-14 09:40:02

标签: ios swift camera

以下代码在使用相机拍摄照片时效果很好,但是当用户点按视频时应用会崩溃。

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

1 个答案:

答案 0 :(得分:11)

我遇到了类似的问题,原因是我的Info.plist没有要求麦克风使用权限。

检查您是否具有适当的值:

  • NSCameraUsageDescriptionPrivacy - Camera Usage Description
  • NSMicrophoneUsageDescriptionPrivacy - Microphone Usage Description
  • NSPhotoLibraryUsageDescriptionPrivacy - Photo Library Usage Description

然后当您从照片模式更改为视频模式时,您的应用会请求麦克风访问,而不仅仅是崩溃。

相关问题