From 3e277338bbbbe0ab135b713bdc6e0f6681994d6e Mon Sep 17 00:00:00 2001 From: Marcin Stepnowski Date: Fri, 27 Jan 2023 16:30:31 +0100 Subject: [PATCH] fix: open scanner even if no camera permission --- ScanNow/generated/Strings.swift | 10 -------- .../localizable/en.lproj/Localizable.strings | 4 ---- .../localizable/pl.lproj/Localizable.strings | 4 ---- ScanNow/scanner/ScannerViewController.swift | 4 ++++ ScanNow/welcome/WelcomeViewController.swift | 23 +------------------ 5 files changed, 5 insertions(+), 40 deletions(-) diff --git a/ScanNow/generated/Strings.swift b/ScanNow/generated/Strings.swift index 6ecb11b..7aa433a 100644 --- a/ScanNow/generated/Strings.swift +++ b/ScanNow/generated/Strings.swift @@ -80,16 +80,6 @@ internal enum Strings { internal static let scan = Strings.tr("Localizable", "welcome.scan", fallback: "Scan Now!") /// Settings internal static let settings = Strings.tr("Localizable", "welcome.settings", fallback: "Settings") - internal enum NoCamera { - /// Cancel - internal static let cancel = Strings.tr("Localizable", "welcome.noCamera.cancel", fallback: "Cancel") - /// The application requires access to the camera to be able to scan documents. - internal static let description = Strings.tr("Localizable", "welcome.noCamera.description", fallback: "The application requires access to the camera to be able to scan documents.") - /// Go to settings - internal static let settings = Strings.tr("Localizable", "welcome.noCamera.settings", fallback: "Go to settings") - /// No camera access - internal static let title = Strings.tr("Localizable", "welcome.noCamera.title", fallback: "No camera access") - } } } // swiftlint:enable explicit_type_interface function_parameter_count identifier_name line_length diff --git a/ScanNow/localizable/en.lproj/Localizable.strings b/ScanNow/localizable/en.lproj/Localizable.strings index 907d9f9..2b93402 100644 --- a/ScanNow/localizable/en.lproj/Localizable.strings +++ b/ScanNow/localizable/en.lproj/Localizable.strings @@ -1,9 +1,5 @@ "welcome.scan" = "Scan Now!"; "welcome.settings" = "Settings"; -"welcome.noCamera.title" = "No camera access"; -"welcome.noCamera.description" = "The application requires access to the camera to be able to scan documents."; -"welcome.noCamera.settings" = "Go to settings"; -"welcome.noCamera.cancel" = "Cancel"; "settings.title" = "Settings"; diff --git a/ScanNow/localizable/pl.lproj/Localizable.strings b/ScanNow/localizable/pl.lproj/Localizable.strings index 557d3a8..7f1ae30 100644 --- a/ScanNow/localizable/pl.lproj/Localizable.strings +++ b/ScanNow/localizable/pl.lproj/Localizable.strings @@ -1,9 +1,5 @@ "welcome.scan" = "Skanuj Teraz!"; "welcome.settings" = "Ustawienia"; -"welcome.noCamera.title" = "Brak dostępu do kamery"; -"welcome.noCamera.description" = "Aplikacja wymaga dostępu do kamery aby móc skanować dokumenty. Przejść do ustawień?"; -"welcome.noCamera.settings" = "Ustawienia"; -"welcome.noCamera.cancel" = "Anuluj"; "settings.title" = "Ustawienia"; diff --git a/ScanNow/scanner/ScannerViewController.swift b/ScanNow/scanner/ScannerViewController.swift index 5c606b1..e2aa1b2 100644 --- a/ScanNow/scanner/ScannerViewController.swift +++ b/ScanNow/scanner/ScannerViewController.swift @@ -63,4 +63,8 @@ extension ScannerViewController: VNDocumentCameraViewControllerDelegate { func documentCameraViewControllerDidCancel(_: VNDocumentCameraViewController) { navigationController?.popViewController(animated: true) } + + func documentCameraViewController(_: VNDocumentCameraViewController, didFailWithError _: Error) { + navigationController?.popViewController(animated: true) + } } diff --git a/ScanNow/welcome/WelcomeViewController.swift b/ScanNow/welcome/WelcomeViewController.swift index fd760f3..7fc0ea9 100644 --- a/ScanNow/welcome/WelcomeViewController.swift +++ b/ScanNow/welcome/WelcomeViewController.swift @@ -20,27 +20,6 @@ final class WelcomeViewController: UIViewController { } private func openScanner() { - if AVCaptureDevice.authorizationStatus(for: .video) == .authorized { - navigationController?.pushViewController(ScannerViewController(), animated: true) - } else { - let strings = Strings.Welcome.NoCamera.self - let alertVC = UIAlertController( - title: strings.title, - message: strings.description, - preferredStyle: .alert - ) - alertVC.addAction(UIAlertAction( - title: strings.settings, - style: .default, - handler: { _ in - guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else { - return - } - UIApplication.shared.open(settingsUrl) - } - )) - alertVC.addAction(UIAlertAction(title: strings.cancel, style: .destructive)) - present(alertVC, animated: true, completion: nil) - } + navigationController?.pushViewController(ScannerViewController(), animated: true) } }