它在其他演示中运行良好,但是在我的项目中崩溃了。我用谷歌搜索'CAMPreviewViewController'但什么都没有

UIImagePickerController * picker=[[UIImagePickerController alloc]init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.allowsEditing = NO;
picker.delegate = self;
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
[self presentViewController:picker animated:YES completion:nil];

CRASH

最佳答案

试试这个

    var imagePicker: UIImagePickerController!

 @IBAction func takePhotoAction(_ sender: UIButton) {
        imagePicker =  UIImagePickerController()
        imagePicker.delegate = self
        imagePicker.sourceType = .camera
        present(imagePicker, animated: true, completion: nil)
    }

Add This to class as delegates

 UINavigationControllerDelegate, UIImagePickerControllerDelegate

关于ios - 在iOS 13中使用UIImagePickerController时崩溃,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58481517/

10-13 03:23