Xcode Camera: Failed to read exposureBiasesByMode dictionary

Viewed 9604

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?

9 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.

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/>

I got this error when I tried to copy from a URL I couldn't copy. Which was coming from the mediaURL from the UIImagePickerControllerDelegate.

Basically, what I did was to use UISaveVideoAtPathToSavedPhotosAlbum

Like in this example ⤵️

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

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!

I found the same error with Xcode 12 & iOS 14 when imagePicker's source type is camera.

But the app is working fine, I could take picture using camera and put it in my collection view cell. Thus, maybe something on Xcode 12 I guess.

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

I faced the same error with Xcode 12 & iOS 14.

But in my case, I used ActionSheet to choose camera or photo library before that. So I changed to open camera just after close that ActionSheet, and it works well.

Hope this will be helpful on your issue.

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

In my case, I was missing an Info.plist key for NSCameraUsageDescription. You should enter the purpose of using camera as the description. It fixed the crash for me. Plus, if you don't give the purpose, your app is likely to be rejected.

I managed to solve the problem. In fact, it is not directly related to react-native-image-crop-picker. The problem was that I was using react-native-actionsheet to give the user the option to open the camera or the gallery. When I opened the react-native-actionsheet and pressed one of the options, the camera was superimposing the react-native-actionsheet (modal) which generated a conflict, because apparently in IOS it is not possible for one Modal to overlap the other.

So, to solve the problem, I defined a timeout so that it is possible to close the modal before opening the camera.

If like me you have this second message :

[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.

Then you have to add this to your info.plist dictionary:

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

It solved the problem for me

Related