当按下从后向前翻转照相机的按钮时,我的应用程序冻结。我仅在 iPhone XS / XS Max 中遇到此问题。 但是,当我从此类视图控制器运行应用程序时,一切正常。
请帮助我解决此问题。
class UploadViewController: UITableViewController,UINavigationControllerDelegate, UIImagePickerControllerDelegate {
var imagePicker = UIImagePickerController()
override func viewDidLoad() {
super.viewDidLoad()
DispatchQueue.main.async {
checkCameraPermission()
}
}
//Camera access
func camera()
{
if(UIImagePickerController .isSourceTypeAvailable(UIImagePickerController.SourceType.camera)){
imagePicker.sourceType = UIImagePickerController.SourceType.camera
imagePicker.mediaTypes = ["public.image"]
imagePicker.allowsEditing = true
imagePicker.delegate = self
self.present(imagePicker, animated: true, completion: nil)
}
else{
let alert = UIAlertController(title: "Warning", message: "You don't have camera", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
}
extension UploadViewController {
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let image = info[.editedImage] as? UIImage {
self.imagePickedBlock?(image)
self.appImage = image
self.imageView.image = image
UIImageWriteToSavedPhotosAlbum(image, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)
// let imageData = image.pngData()! as NSData
}
else {
print("No image found")
return
}
picker.dismiss(animated: true, completion: nil)
}
调试器向我抛出此错误:
线程48:EXC_BAD_ACCESS(code = 2,address = 0 * 16b142640)