Xcode Camera:无法读取exposureBiasesByMode字典



我最近在Xcode 12.0.1版中的UIImagePickerController中遇到了这个错误

[Camer]无法读取exposureBiasesByMode字典:错误域=NSCocoaErrorDomain代码=4864"***-[NSKeyedUnarchiver _initForReadingFromData:错误:throwLegacyExceptions:]:数据为NULL"用户信息={NSDebugDescription=***-[NSKeyedUnarchiver_initForReadingFromData:错误:throwLegacyExceptions:]:数据为NULL}

是否有其他人看到此错误?你是怎么修的?

如果将图像选择器自定义为imagePicker.allowsEditing = true您必须使用获取图像

if let pickedImage = info[UIImagePickerController.InfoKey.editedImage] as? UIImage {
capturedImage = pickedImage    
}

如果您改为使用imagePicker.allowsEditing = false,请使用此选项拾取图像:

if let pickedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
capturedImage = pickedImage        
}

如果你不遵循这个组合,你可能会得到这个错误。

在我的案例中,我在尝试使用图像数据和与Files同步时遇到了这个错误。在Info.plist中添加这个权限使所有的区别都消失了:

<key>LSSupportsOpeningDocumentsInPlace</key> <true/>

我遇到了同样的问题。我导入了AVKit而不是ogAVFoundation,并尝试在本机记录器视图中显示视频。这给了我一个异常,告诉我将NSMicrophoneUsageDescription添加到info.plist文件中,之后,我可以在自定义视图中显示实时视频。

因此,我认为问题在于iOS 14对权限非常挑剔,当视频未在本机视图中显示时,显示正确的异常可能会出现问题。

不管怎样,这对我有效:

import AVKit
import MobileCoreServices
@IBOutlet weak var videoViewContainer: UIView!
private let imagePickerController = UIImagePickerController()
override func viewDidLoad() {
super.viewDidLoad()
initCameraView()
}
func initCameraView() {
// Device setup
imagePickerController.delegate = self
imagePickerController.sourceType = .camera
imagePickerController.mediaTypes = [kUTTypeMovie as String]
imagePickerController.cameraCaptureMode = .video
imagePickerController.cameraDevice = .rear

// UI setup
addChild(imagePickerController)
videoViewContainer.addSubview(imagePickerController.view)
imagePickerController.view.frame = videoViewContainer.bounds
imagePickerController.allowsEditing = false
imagePickerController.showsCameraControls = false
imagePickerController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
}

然后在info.plist文件中添加对NSMicrophoneUsageDescription的描述:-(

希望它对你也有用!

我设法解决了这个问题。事实上,它与react原生图像裁剪选择器没有直接关系。问题是,我使用react native actionsheet为用户提供打开相机或图库的选项。当我打开react native actionsheet并按下其中一个选项时,相机正在叠加react nature actionsheet(modal(,这产生了冲突,因为显然在IOS中,一个modal不可能与另一个重叠。

因此,为了解决这个问题,我定义了一个超时,这样就可以在打开相机之前关闭模态。

当我试图从无法复制的URL进行复制时,出现了此错误。来自CCD_ 9和CCD_。

基本上,我所做的是使用UISaveVideoAtPathToSavedPhotosAlbum

就像这个例子一样⤵️

if UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(url.absoluteString) {
UISaveVideoAtPathToSavedPhotosAlbum(url.absoluteString, self, #selector(self.didSaveVideo), nil)
} else {
return /* do something*/
}
@objc private func didSaveVideo(videoPath: String, error: NSError, contextInfo: Any) {}

我在Xcode 12&iOS 14,当imagePicker的源类型为相机时。

但该应用程序运行良好,我可以用相机拍照,并将其放在我的收藏视图单元格中。因此,我想可能是Xcode 12上的一些东西。

@objc func addPerson() {
let picker = UIImagePickerController()
if UIImagePickerController.isSourceTypeAvailable(.camera) {
picker.sourceType = .camera
} else {
fatalError("Camera is not available, please use real device.")
}
picker.allowsEditing = true
picker.delegate = self
present(picker, animated: true)
}

我在Xcode 12&iOS 14。

但在我的情况下,在此之前,我使用ActionSheet来选择相机或照片库。所以我在关闭ActionSheet后就改为打开相机,效果很好。

希望这对你的问题有帮助。


enum MediaOptions: Int {
case Photos
case Camera
}
func selectImage(mediaType: MediaOptions) {
self.mediaOption = mediaType
let iPicker = UIImagePickerController()
iPicker.delegate = self
iPicker.allowsEditing = false
if mediaType == .Camera {
if UIImagePickerController.isSourceTypeAvailable(.camera) {
iPicker.sourceType = .camera
iPicker.allowsEditing = true
}
} else {
iPicker.sourceType = .photoLibrary
}
self.present(iPicker, animated: true, completion: nil)
self.imagePicker = iPicker
}
func choosePhoto() {
let actionSheet = UIAlertController(title: "Choose", message: "", preferredStyle: .actionSheet)

if UIImagePickerController.isSourceTypeAvailable(.camera) {
actionSheet.addAction(UIAlertAction(title: "Camera", style: .default, handler: { (action) -> Void in
actionSheet.dismiss(animated: true) {
self.selectImage(mediaType: .Camera) // Just moved here - inside the dismiss callback
}
}))
}
if UIImagePickerController.isSourceTypeAvailable(.photoLibrary) {
actionSheet.addAction(UIAlertAction(title: "Photo Library", style: .default, handler: { (action) -> Void in
self.selectImage(mediaType: .Photos)
}))
}

actionSheet.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))

self.present(actionSheet, animated: true, completion: nil)
}

在我的情况下,NSCameraUsageDescription缺少一个Info.plist键。您应该输入使用相机的目的作为描述。它帮我修好了车祸。此外,如果你不给出目的,你的应用程序很可能会被拒绝。

如果你和我一样,有第二条消息:

[access] This app has crashed because it attempted to access privacy-sensitive data without a usage description.  The app's Info.plist must contain an NSCameraUsageDescription key with a string value explaining to the user how the app uses this data.

然后你必须将其添加到你的info.plist字典中:

<key>NSCameraUsageDescription</key>
<string>so you can choose a photo or take a picture for object detection</string>

它为我解决了问题

最新更新