iOS UIImagePickerController showed blank page

蓝咒 提交于 2021-02-10 09:58:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!