Presentation is in process issue following Error

Viewed 364

I am playing with Vision for text recognition, I present the camera, take a photo and the text is detected and processed...running very well. The issue I have is when there is no text in the photo, I get an error from VNImageRequestHandler, which is fine, but the issue is that I can't re-open the camera, I get "Warning: Attempt to present UIImagePickerController: ... while a presentation is in progress!.

here is some code where I process the image looking for some text...

guard let image = image, let cgImage = image.cgImage else { return }

    let requests = [textDetectionRequest]
    let imageRequestHandler = VNImageRequestHandler(cgImage: cgImage, orientation: .up, options: [:] )
    DispatchQueue.global(qos: .userInitiated).async {
        do {
            try imageRequestHandler.perform(requests)
        } catch let error {
            print("Error: \(error)")
        }
    }
}

the Error is

"Error: Error Domain=com.apple.vis Code=11 "encountered unknown exception" UserInfo={NSLocalizedDescription=encountered unknown exception}"

which is fine, I just want to be able to open the UIImagePickerController after that Error.

I have tried to dismiss the UIImagePickerController, does not work... and I can't find what presentation is really in process.

Thanks.

1 Answers

For me it was something completely unrelated that caused this error. After the VNRequestCompletionHandler was called, I attempted to initialize a malformed NSPredicate. Then I would get the error that you described. Fixing the predicate also fixed the issue you described.

I would look to see if there's any work you're doing after the completion handler is called that can throw an error and fix that.

Related