点击视频按钮时UIImagePickerController崩溃

Ant*_*par 3 camera ios swift

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

 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)
     }
 }
Run Code Online (Sandbox Code Playgroud)

小智 14

我有一个类似的问题,这是由于我没有要求麦克风使用许可Info.plist.

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

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

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