Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImagePickerController extension discovery failed with error: (null)

I'm trying to implement an ImagePicker on my ViewController, but turns out it presents a blank ImagePicker Controller and UIImagePickerController extension discovery failed with error: (null) message on the console.

I have no idea what I'm doing wrong, and I found no information on the matter. One thing I noticed, though, is that the PickerView takes a little bit too long to be presented.

The code related to the ImagePicker is the following:

private let imagePicker = UIImagePickerController()

private func setupImagePicker() {
        imagePicker.sourceType = .photoLibrary
        imagePicker.allowsEditing = false
        imagePicker.delegate = self
        imagePicker.mediaTypes = ["public.image"]
}

    @objc private func launchImagePicker() {

        let photos = PHPhotoLibrary.authorizationStatus()
        if photos == .notDetermined {
            PHPhotoLibrary.requestAuthorization({ [weak self] status in
                DispatchQueue.main.async {
                    if status == .authorized, let picker = self?.imagePicker {
                        self?.present(picker, animated: true, completion: nil)
                    } else {
                        self?.present(URealtorUtils.getAlert(message: "You have to authorize photo library access in order to upload a photo"), animated: true, completion: nil)
                    }
                }
            })
        } else if photos == .authorized {
            present(imagePicker, animated: true, completion: nil)
        }
    }

extension MyController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {

    func imagePickerController(_ picker: UIImagePickerController,
                               didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
        if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
            self.viewModel.setPropertyImage(image)
        }
        dismiss(animated: true, completion: nil)
    }

    func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
        dismiss(animated: true, completion: nil)
    }
}

This is a screenshot of what I get when the PickerView is presented:

like image 940
CaMenz Avatar asked Feb 22 '20 22:02

CaMenz


1 Answers

I checked the details, and there are no issues in your implementation. I also checked the apple's official sample here. https://developer.apple.com/documentation/uikit/uiimagepickercontroller/customizing_an_image_picker_controller Same result!

Finally, this is an issue related to iOS Simulators(version 11.3.1). FYI, I found iPhone 11 Pro Max didn't work in some previous versions, but iPhone 8 and some others worked. I just want you guys not wasting time on this. Move ahead.

Thanks.

like image 112
Software Engineer Avatar answered Sep 18 '22 01:09

Software Engineer