Skip to content

Commit

Permalink
fix: open scanner even if no camera permission
Browse files Browse the repository at this point in the history
  • Loading branch information
WezSieTato committed Jan 28, 2023
1 parent 55a2ca1 commit 3e27733
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 40 deletions.
10 changes: 0 additions & 10 deletions ScanNow/generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions ScanNow/localizable/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
4 changes: 0 additions & 4 deletions ScanNow/localizable/pl.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
4 changes: 4 additions & 0 deletions ScanNow/scanner/ScannerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,8 @@ extension ScannerViewController: VNDocumentCameraViewControllerDelegate {
func documentCameraViewControllerDidCancel(_: VNDocumentCameraViewController) {
navigationController?.popViewController(animated: true)
}

func documentCameraViewController(_: VNDocumentCameraViewController, didFailWithError _: Error) {
navigationController?.popViewController(animated: true)
}
}
23 changes: 1 addition & 22 deletions ScanNow/welcome/WelcomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 3e27733

Please sign in to comment.