UIImagePickerController extension discovery failed with error: (null)
UIImagePickerController extension discovery failed with error: (null)
我试图在我的 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 时我得到的屏幕截图:
我检查了细节,你的实现没有问题。
我这里也查了苹果的官方样本。
https://developer.apple.com/documentation/uikit/uiimagepickercontroller/customizing_an_image_picker_controller
结果相同!
最后,这是一个与 iOS 模拟器(版本 11.3.1)相关的问题。
仅供参考,我发现 iPhone 11 Pro Max 在某些以前的版本中不起作用,但 iPhone 8 和其他一些版本有效。
我只是希望你们不要在这上面浪费时间。继续前进。
谢谢。
我试图在我的 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 时我得到的屏幕截图:
我检查了细节,你的实现没有问题。 我这里也查了苹果的官方样本。 https://developer.apple.com/documentation/uikit/uiimagepickercontroller/customizing_an_image_picker_controller 结果相同!
最后,这是一个与 iOS 模拟器(版本 11.3.1)相关的问题。 仅供参考,我发现 iPhone 11 Pro Max 在某些以前的版本中不起作用,但 iPhone 8 和其他一些版本有效。 我只是希望你们不要在这上面浪费时间。继续前进。
谢谢。