Skip to content

Instantly share code, notes, and snippets.

@sgl0v
Created June 2, 2021 19:20
Show Gist options
  • Save sgl0v/5f5397339a0e773903ffa5dda1e55df0 to your computer and use it in GitHub Desktop.
Save sgl0v/5f5397339a0e773903ffa5dda1e55df0 to your computer and use it in GitHub Desktop.
final class ImageScanner: NSObject {
private var completion: Completion?
func image(with completion: @escaping Completion) {
guard self.completion == nil, UIImagePickerController.isSourceTypeAvailable(.camera) else {
completion(.failure(ImageProviderError.startFailure))
return
}
self.completion = completion
let pickerController = UIImagePickerController()
pickerController.delegate = self
pickerController.sourceType = .camera
UIViewController.topmostViewContoller.present(pickerController, animated: true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment