问题描述
我正在尝试在我的 ViewController 上实现一个 ImagePicker,但结果它显示了一个空白的 ImagePicker 控制器和 UIImagePickerController 扩展发现失败,错误:(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.
我不知道自己做错了什么,也没有找到有关此事的信息.不过,我注意到的一件事是 PickerView 的显示时间太长了.
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.
ImagePicker 相关代码如下:
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)
}
}
这是我在显示 PickerView 时得到的屏幕截图:
This is a screenshot of what I get when the PickerView is presented:
推荐答案
我查看了详细信息,您的实现没有问题.我还在这里检查了苹果的官方样本.https://developer.apple.com/documentation/uikit/uiimagepickercontroller/customizing_an_image_picker_controller结果一样!
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_controllerSame result!
最后,这是一个与 iOS 模拟器(版本 11.3.1)相关的问题.仅供参考,我发现 iPhone 11 Pro Max 在某些以前的版本中无法使用,但 iPhone 8 和其他一些版本可以使用.我只是希望你们不要在这上面浪费时间.继续前进.
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.
谢谢.
这篇关于UIImagePickerController 扩展发现失败,错误:(空)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!