UIImagePickerController扩展发现失败,错误:(null)

问题描述 投票:0回答:1

我正在尝试在ViewController上实现ImagePicker,但事实证明它在控制台上显示空白ImagePicker控制器和UIImagePickerController extension discovery failed with error: (null)消息。

我不知道我在做什么错,也没有发现有关此事的信息。不过,我注意到的一件事是PickerView花费的时间太长而无法呈现。

与ImagePicker相关的代码如下:

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

这是在显示PickerView时得到的屏幕截图:

ios swift uiimagepickercontroller
1个回答
0
投票

我检查了详细信息,并且您的实现没有问题。我还在这里检查了苹果的官方样品。https://developer.apple.com/documentation/uikit/uiimagepickercontroller/customizing_an_image_picker_controller结果相同!

最后,这是与iOS版本/模拟器有关的问题。我只希望你们不要在此浪费时间。继续前进。

谢谢。

© www.soinside.com 2019 - 2024. All rights reserved.