问题
I tried to present and dismiss the UIImagePickerController continuity
Here is my code
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)
}
Here is the result:
Here is the error log:
UIImagePickerController UIViewController create error: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.mobileslideshow.photo-picker.viewservice was interrupted, but the message was sent over an additional proxy and therefore this proxy has become invalid." UserInfo={NSDebugDescription=The connection to service named com.apple.mobileslideshow.photo-picker.viewservice was interrupted, but the message was sent over an additional proxy and therefore this proxy has become invalid.}
So, what should I do to fix this issue
回答1:
Using Swift 4 there are two pre-requisite for the UIImagePicker
. Check if you have done that
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) Make sure that the info.plist
has the Privacy - Photo library Usage Description
key and String value set.
来源:https://stackoverflow.com/questions/52403232/ios-uiimagepickercontroller-showed-blank-page