我试图展示和消除UIImagePickerController的连续性
这是我的代码
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的服务的连接已中断,但消息是通过其他代理发送的,因此该代理已无效。}
所以,我应该怎么解决这个问题
答案 0 :(得分:0)
使用Swift 4,UIImagePicker
有两个先决条件。检查是否已完成
1)UIImagePickerController的委托是UIImagePickerControllerDelegate & UINavigationControllerDelegate
,因此需要显式添加UINavigationControllerDelegate
作为以下协议之一:
class ViewController:UIViewController, UIImagePickerControllerDelegate,
UINavigationControllerDelegate { .... }
2)确保info.plist
设置了Privacy - Photo library Usage Description
键和字符串值。