问题描述
我试图呈现和关闭 UIImagePickerController 的连续性
I tried to present and dismiss the UIImagePickerController continuity
这是我的代码
var imagePicker = UIImagePickerController()
func viewDidLoad() {
super.viewDidLoad()
imagePicker.allowsEditing = false
imagePicker.delegate = self
}
func showImagePickerController() {
imagePicker.sourceType = .photoLibrary
present(self.imagePicker, animated: true)
}
// MARK: - UIImagePickerControllerDelegate
private func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: Any]) {
if let image = info[UIImagePickerController.InfoKey.originalImage.rawValue] as? UIImage {
imageViewGroup.image = image
isChoosePhoto = true
}
dismiss(animated: true)
}
结果如下:
这是错误日志:
UIImagePickerController UIViewController 创建错误:错误域=NSCocoaErrorDomain 代码=4099与名为 com.apple.mobileslideshow.photo-picker.viewservice 的服务的连接被中断,但消息是通过附加代理发送的,因此该代理已成为无效的."UserInfo={NSDebugDescription=与名为 com.apple.mobileslideshow.photo-picker.viewservice 的服务的连接中断,但消息是通过其他代理发送的,因此该代理已失效.}
那么,我该怎么做才能解决这个问题
So, what should I do to fix this issue
推荐答案
使用 Swift 4,UIImagePicker
有两个先决条件.检查您是否已这样做
Using Swift 4 there are two pre-requisite for the UIImagePicker
. Check if you have done that
1) UIImagePickerController 的委托是 UIImagePickerControllerDelegate &UINavigationControllerDelegate
所以需要显式添加 UINavigationControllerDelegate
作为协议之一:
1) The delegate for the UIImagePickerController is UIImagePickerControllerDelegate & UINavigationControllerDelegate
so need to explicitly add the UINavigationControllerDelegate
as one of the protocols:
class ViewController:UIViewController, UIImagePickerControllerDelegate,
UINavigationControllerDelegate { .... }
2) 确保 info.plist
设置了 Privacy - Photo library Usage Description
键和 String 值.
2) Make sure that the info.plist
has the Privacy - Photo library Usage Description
key and String value set.
这篇关于iOS UIImagePickerController 显示空白页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!