Selaa lähdekoodia

notifications stats: show as 'Disabled' when 'Background App Refresh' is disabled

B. Petersen 3 vuotta sitten
vanhempi
commit
530eae372f

+ 10 - 3
deltachat-ios/Controller/ConnectivityViewController.swift

@@ -42,7 +42,7 @@ class ConnectivityViewController: WebViewViewController {
     }
 
     // this method needs to be run from a background thread
-    private func getNotificationStatus(hasNotifyToken: Bool) -> String {
+    private func getNotificationStatus(hasNotifyToken: Bool, backgroundRefreshStatus: UIBackgroundRefreshStatus) -> String {
         let title = " <b>" + String.localized("pref_notifications") + ":</b> "
         let notificationsEnabledInDC = !UserDefaults.standard.bool(forKey: "notifications_disabled")
         var notificationsEnabledInSystem = false
@@ -71,6 +71,12 @@ class ConnectivityViewController: WebViewViewController {
                 .appending(String.localized("disabled_in_system_settings"))
         }
 
+        if backgroundRefreshStatus != .available {
+            return "<span class=\"disabled dot\"></span>"
+                .appending(title)
+                .appending(String.localized("bg_app_refresh_disabled"))
+        }
+
         if !hasNotifyToken {
             return "<span class=\"red dot\"></span>"
                 .appending(title)
@@ -132,11 +138,12 @@ class ConnectivityViewController: WebViewViewController {
     }
 
     private func loadHtml() {
-        // appDelegate needs to be called from main thread
+        // `UIApplication.shared` needs to be called from main thread
         var hasNotifyToken = false
         if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
             hasNotifyToken = appDelegate.notifyToken != nil
         }
+        let backgroundRefreshStatus = UIApplication.shared.backgroundRefreshStatus
 
         // do the remaining things in background thread
         DispatchQueue.global(qos: .userInitiated).async { [weak self] in
@@ -164,7 +171,7 @@ class ConnectivityViewController: WebViewViewController {
                     </style>
                     """)
 
-            let notificationStatus = self.getNotificationStatus(hasNotifyToken: hasNotifyToken)
+            let notificationStatus = self.getNotificationStatus(hasNotifyToken: hasNotifyToken, backgroundRefreshStatus: backgroundRefreshStatus)
             if let range = html.range(of: "</ul>") {
                 html = html.replacingCharacters(in: range, with: "<li>" + notificationStatus + "</li></ul>")
             }

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

@@ -861,6 +861,7 @@
 "open_settings" = "Open Settings";
 "disabled_in_dc" = "Disabled in Delta Chat";
 "disabled_in_system_settings" = "Disabled in system settings";
+"bg_app_refresh_disabled" = "\"Background App Refresh\" disabled in system settings";
 "delayed" = "Delayed";
 "notifications_avg_minutes" = "On average every %1$d minutes";
 "notifications_avg_hours" = "On average every %1$d hours";

+ 1 - 0
scripts/untranslated.xml

@@ -14,6 +14,7 @@
     <string name="open_settings">Open Settings</string>
     <string name="disabled_in_dc">Disabled in Delta Chat</string>
     <string name="disabled_in_system_settings">Disabled in system settings</string>
+    <string name="bg_app_refresh_disabled">\"Background App Refresh\" disabled in system settings</string>
     <string name="delayed">Delayed</string>
     <string name="notifications_avg_minutes">On average every %1$d minutes</string>
     <string name="notifications_avg_hours">On average every %1$d hours</string>