Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode Camera: Failed to read exposureBiasesByMode dictionary

Tags:

ios

swift

I recently got this error with the UIImagePickerController in Xcode Version 12.0.1

[Camera] Failed to read exposureBiasesByMode dictionary: Error Domain=NSCocoaErrorDomain Code=4864 "*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: data is NULL" UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: data is NULL}

Has anyone else seen this error? How do you fix it?

like image 223
r.gasser Avatar asked Sep 25 '20 09:09

r.gasser


3 Answers

If you customize your image picker as imagePicker.allowsEditing = true you have to fetch image using:

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

If you instead use imagePicker.allowsEditing = false, use this to pick image:

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

If you don't follow this combination, you may get this error.

like image 78
Ömer Karaca Avatar answered Nov 14 '22 21:11

Ömer Karaca


in my case, I got this bug from trying to use the image data and syncing with Files. Adding this permission in Info.plist made all the difference and made that error go away:

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

like image 29
naomi Avatar answered Nov 14 '22 22:11

naomi


I experienced the same issue. I imported AVKit instead og AVFoundation and tried to present the video in the native recorder view. That gave me an exception telling me to add NSMicrophoneUsageDescription to the info.plist file, and after this, I was able to display the live video in a custom view.

So I believe the issue is with iOS 14 being very picky about permissions, and probably something goes wrong with showing the correct exception when the video is not presented in the native view.

Anyway, this worked for me:

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

And then the added description for the NSMicrophoneUsageDescription in the info.plist file :-)

Hope it will work for you as well!

like image 45
Nicolai Harbo Avatar answered Nov 14 '22 22:11

Nicolai Harbo