谁能告诉我为什么当我按下摄像头按钮时我的应用程序崩溃了
Can someone please tell me why my apps crashes when I press the cam button
我有一个 class 选择删除,之后我的添加一直崩溃。
下面是按钮中的内容
@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
// }
//}
崩溃可能仅仅是因为这些:
- 没有向 info.plist 添加所需的权限(在这种情况下,您将在日志中收到消息,指出 .plist 文件中缺少权限。
- 对象未连接到正确的 IBOutlet(在这种情况下,文件中 IBOutlet 旁边的圆圈将为空,这意味着它未连接到任何对象。)
对于您的情况,您的 info.plist 中缺少许可。您应该添加 NSCameraUsageDescription
并且该值是一个字符串,当询问用户打开相机的权限时,该字符串将显示在权限对话框中。它将是这样的:
我有一个 class 选择删除,之后我的添加一直崩溃。
下面是按钮中的内容
@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
// }
//}
崩溃可能仅仅是因为这些:
- 没有向 info.plist 添加所需的权限(在这种情况下,您将在日志中收到消息,指出 .plist 文件中缺少权限。
- 对象未连接到正确的 IBOutlet(在这种情况下,文件中 IBOutlet 旁边的圆圈将为空,这意味着它未连接到任何对象。)
对于您的情况,您的 info.plist 中缺少许可。您应该添加 NSCameraUsageDescription
并且该值是一个字符串,当询问用户打开相机的权限时,该字符串将显示在权限对话框中。它将是这样的: