我试图在我的 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 https://developer.apple.com/documentation/uikit/uiimagepickercontroller/customizing_an_image_picker_controller结果一样!
最后,这是与iOS模拟器(版本11.3.1)相关的问题。
仅供参考,我发现 iPhone 11 Pro Max 在某些以前的版本中无法使用,但 iPhone 8 和其他一些版本可以使用。
我只是希望你们不要在这上面浪费时间。前进。
Thanks.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)