当我使用UIImagePickerControllerSourceType.camera时,以未捕获的异常终止

时间:2017-02-23 16:46:51

标签: ios swift xcode error-handling

enter image description here

@IBAction func onlytest(_ sender: Any) {

        let imagePickerController = UIImagePickerController()
        imagePickerController.delegate = self

        let actionSheet = UIAlertController(title: "Choose image source", message: nil, preferredStyle: UIAlertControllerStyle.actionSheet)

        actionSheet.addAction(UIAlertAction(title: "Camera roll", style: UIAlertActionStyle.default, handler: { ( alert: UIAlertAction!) -> Void in
            imagePickerController.sourceType = UIImagePickerControllerSourceType.photoLibrary
            self.present(imagePickerController, animated: true, completion: nil)
        } ))

        actionSheet.addAction(UIAlertAction(title: "Take Photo", style: UIAlertActionStyle.default, handler: { ( alert: UIAlertAction!) -> Void in
            imagePickerController.sourceType = UIImagePickerControllerSourceType.camera
            self.present(imagePickerController, animated: true, completion: nil)
        } ))

        actionSheet.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil))

        self.present(actionSheet, animated: true, completion: nil)



    }

当我点击拍照时,我收到以下错误:

  

libc ++ abi.dylib:以NSException类型的未捕获异常终止“使应用程序崩溃

然而,当我点击相机胶卷时,它可以正常工作。

连接没有错误。有没有人有想法?

0 个答案:

没有答案