有人可以告诉我为什么当我按下cam按钮时我的应用程序崩溃吗

时间:2019-04-28 03:28:13

标签: swift uiimagepickercontroller

我有一个要删除的类,之后我的添加项一直崩溃。

下面是按钮

@IBAction func cameraButton_TouchUpInside(_ sender: Any) {
        let imagePickerController = ImagePickerController()
        imagePickerController.delegate = self
        imagePickerController.imageLimit = 1
        present(imagePickerController, animated: true, completion: nil)
    }

func wrapperDidPress(_ imagePicker: ImagePickerController, images: [UIImage]) {

    }
    func doneButtonDidPress(_ imagePicker: ImagePickerController, images: [UIImage]) {
        guard let image = images.first else {
            dismiss(animated: true, completion: nil)
            return
        }


   if let image = info["UIImagePickerControllerOriginalImage"] as? UIImage{
            selectedImage = image
            photo.image = image
            dismiss(animated: true, completion: nil)
//            dismiss(animated: true, completion: {
//                self.performSegue(withIdentifier: "Camera", sender: nil)
//            })
        }

如果我取消注释,当我尝试从库中进行选择时,我的应用程序崩溃上方的内容

更多

//    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
//        if segue.identifier == "filter_segue" {
//            let filterVC = segue.destination as! FilterViewController
//            filterVC.selectedImage = self.selectedImage
//            filterVC.delegate = self
//        }
   // }

//extension CameraViewController: FilterViewControllerDelegate {
//    func updatePhoto(image: UIImage) {
//        self.photo.image = image
//        self.selectedImage = image
//    }
//}

1 个答案:

答案 0 :(得分:1)

崩溃的原因可能仅仅是这些:

  • 没有向info.plist添加必需的权限(在这种情况下,您会在日志中收到消息,表明.plist文件中缺少该权限。
  • 对象未连接到正确的IBOutlet(在这种情况下,文件中IBOutlet旁边的圆圈为空,这意味着它未连接到任何对象。)

您的案例权限未在info.plist中。您应该添加NSCameraUsageDescription并且该值是一个字符串,当询问用户打开摄像机的权限时,该字符串将显示在权限对话框中。会是这样的:

enter image description here