Bläddra i källkod

show an alert and lead the user to the app settings

cyberta 4 år sedan
förälder
incheckning
5670c21f07

+ 20 - 4
deltachat-ios/Controller/QrCodeReaderController.swift

@@ -49,7 +49,8 @@ class QrCodeReaderController: UIViewController {
                 if granted {
                     self.setupQRCodeScanner()
                 } else {
-                    self.setInfoWarning(text: "You need to give Delta Chat the camera permission in order to use the QR-Code scanner")
+                    self.setInfoWarning()
+                    self.showPermissionAlert()
                 }
             })
         }
@@ -81,7 +82,7 @@ class QrCodeReaderController: UIViewController {
             deviceTypes: [AVCaptureDevice.DeviceType.builtInWideAngleCamera],
             mediaType: .video,
             position: .back).devices.first else {
-            self.setInfoWarning(text: "Failed to get the camera device. It might be occupied by another app.")
+            self.setInfoWarning()
             return
         }
         do {
@@ -95,7 +96,7 @@ class QrCodeReaderController: UIViewController {
             captureMetadataOutput.metadataObjectTypes = self.supportedCodeTypes
         } catch {
             // If any error occurs, simply print it out and don't continue any more.
-            self.setInfoWarning(text: "failed to setup QR Code Scanner: \(error)")
+            self.setInfoWarning()
             return
         }
         view.layer.addSublayer(videoPreviewLayer)
@@ -113,9 +114,10 @@ class QrCodeReaderController: UIViewController {
         view.bringSubviewToFront(infoLabel)
     }
     
-    private func setInfoWarning(text: String) {
+    private func setInfoWarning() {
         DispatchQueue.main.async { [weak self] in
             guard let self = self else { return }
+            let text = String.localized("chat_camera_unavailable")
             logger.error(text)
             self.infoLabel.textColor = DcColors.defaultTextColor
             self.infoLabel.text = text
@@ -124,6 +126,20 @@ class QrCodeReaderController: UIViewController {
         }
     }
     
+    private func showPermissionAlert() {
+        DispatchQueue.main.async { [weak self] in
+            let alert = UIAlertController(title: String.localized("perm_required_title"),
+                                          message: String.localized("perm_ios_explain_access_to_camera_denied"),
+                                          preferredStyle: .alert)
+            if let appSettings = URL(string: UIApplication.openSettingsURLString) {
+                alert.addAction(UIAlertAction(title: String.localized("open_settings"), style: .default, handler: { _ in
+                        UIApplication.shared.open(appSettings, options: [:], completionHandler: nil)}))
+                alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .destructive, handler: nil))
+            }
+            self?.present(alert, animated: true, completion: nil)
+        }
+    }
+    
     private func updateVideoOrientation() {
 
         guard let connection = videoPreviewLayer.connection else {

+ 2 - 0
deltachat-ios/en.lproj/Localizable.strings

@@ -770,3 +770,5 @@
 "login_error_no_internet_connection" = "No internet connection, can\'t log in to your server.";
 "share_account_not_configured" = "Account is not configured.";
 "cannot_play_unsupported_file_type" = "The audio file cannot be played.";
+"perm_ios_explain_access_to_camera_denied" = "To use the QR-Code scanner, take photos or capture videos, open the system settings, and enable \"Camera\".";
+"open_settings" = "Open Settings";

+ 3 - 0
scripts/untranslated.xml

@@ -9,4 +9,7 @@
     <string name="login_error_no_internet_connection">No internet connection, can\'t log in to your server.</string>
     <string name="share_account_not_configured">Account is not configured.</string>
     <string name="cannot_play_unsupported_file_type">The audio file cannot be played.</string>
+    
+    <string name="perm_ios_explain_access_to_camera_denied">To use the QR-Code scanner, take photos or capture videos, open the system settings, and enable \"Camera\".</string>
+    <string name="open_settings">Open Settings</string>
 </resources>