UIImagePickerController关闭崩溃

问题描述 投票:0回答:1

我在Xcode 11.3中实现标准相机功能时遇到麻烦。当我单击“使用照片”按钮时,应用程序崩溃。单击“重新录制”按钮效果很好。

@IBAction func onPhotoButton(_ sender: Any) {

    let imagePickerController = UIImagePickerController()
    imagePickerController.delegate = self
    imagePickerController.sourceType = UIImagePickerController.SourceType.camera
    present(imagePickerController, animated: true, completion: nil)
}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any])
{
    imagePickerController.dismiss(animated: true) // crashes on this line!
    imageView.image = info[.originalImage] as? UIImage
}

崩溃发生在.dismiss行上。错误是“致命错误:意外地发现了nil,同时隐式展开了一个可选值:“

我查看了以前关于类似问题的帖子,似乎没有一个可以解决这个问题。

xcode uiimagepickercontroller
1个回答
0
投票

在将违规行更改为]时有效>

 picker.dismiss(animated: true)
© www.soinside.com 2019 - 2024. All rights reserved.