iOS UIImagePickerController显示空白页

时间:2018-09-19 10:01:29

标签: ios uiimagepickercontroller

我试图展示和消除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)
}

结果如下:

plant page

以下是错误日志:

  

UIImagePickerController UIViewController创建错误:错误域= NSCocoaErrorDomain代码= 4099“与名为com.apple.mobileslideshow.photo-picker.viewservice的服务的连接已中断,但消息已通过其他代理发送,因此该代理已变为无效。” UserInfo = {NSDebugDescription =与名为com.apple.mobileslideshow.photo-picker.viewservice的服务的连接已中断,但消息是通过其他代理发送的,因此该代理已无效。}

所以,我应该怎么解决这个问题

1 个答案:

答案 0 :(得分:0)

使用Swift 4,UIImagePicker有两个先决条件。检查是否已完成

1)UIImagePickerController的委托是UIImagePickerControllerDelegate & UINavigationControllerDelegate,因此需要显式添加UINavigationControllerDelegate作为以下协议之一:

class ViewController:UIViewController, UIImagePickerControllerDelegate, 
UINavigationControllerDelegate { .... } 

2)确保info.plist设置了Privacy - Photo library Usage Description键和字符串值。