UIImagePickerController extension discovery failed with error: (null)

吃可爱长大的小学妹 提交于 2020-03-20 05:58:10

问题


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:


回答1:


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.



来源:https://stackoverflow.com/questions/60357610/uiimagepickercontroller-extension-discovery-failed-with-error-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!