Ver código fonte

add debug counter for notifications

B. Petersen 4 anos atrás
pai
commit
f7221f8898

+ 14 - 2
deltachat-ios/AppDelegate.swift

@@ -76,8 +76,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
             logger.error("Unable to start notifier")
         }
         
-        let notificationOption = launchOptions?[.remoteNotification]
-        logger.info("Notifications: remoteNotification: \(String(describing: notificationOption))")
+        if let notificationOption = launchOptions?[.remoteNotification] {
+            logger.info("Notifications: remoteNotification: \(String(describing: notificationOption))")
+            increaseDebugCounter("notify-remote-launch")
+        }
 
         if dcContext.isConfigured() && !UserDefaults.standard.bool(forKey: "notifications_disabled") {
             registerForNotifications()
@@ -111,6 +113,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     // also, the faster we return, the sooner we get called again.
     func application(_: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
         logger.info("---- background-fetch ----")
+        increaseDebugCounter("notify-local-wakeup")
 
         dcContext.maybeStartIo()
         dcContext.maybeNetwork()
@@ -367,11 +370,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         _ application: UIApplication,
         didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
         logger.verbose("Notifications: didReceiveRemoteNotification \(userInfo)")
+        increaseDebugCounter("notify-remote-receive")
 
         dcContext.maybeStartIo()
         dcContext.maybeNetwork()
     }
 
+    private func increaseDebugCounter(_ name: String) {
+        let cnt = UserDefaults.standard.integer(forKey: name + "-cnt")
+        UserDefaults.standard.set(cnt + 1, forKey: name + "-cnt")
+
+        let timestamp = Double(Date().timeIntervalSince1970)
+        UserDefaults.standard.set(timestamp, forKey: name + "-name")
+    }
+
 
     // MARK: - Handle notification banners
 

+ 11 - 0
deltachat-ios/Controller/SettingsController.swift

@@ -468,6 +468,13 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
         navigationController?.pushViewController(HelpViewController(), animated: true)
     }
 
+    private func formatDebugCounter(_ name: String) -> String {
+        let val = UserDefaults.standard.integer(forKey: name + "-cnt")
+        let timestampInt = UserDefaults.standard.double(forKey: name + "-name")
+        let timestampStr = DateUtils.getExtendedRelativeTimeSpanString(timeStamp: timestampInt)
+        return "\(val) times, last time: \(timestampStr) (\(timestampInt))"
+    }
+
     private func showDebugToolkit() {
         var info: [DBCustomVariable] = dcContext.getInfo().map { kv in
             let value = kv.count > 1 ? kv[1] : ""
@@ -481,6 +488,10 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
         #endif
 
 
+        info.append(DBCustomVariable(name: "notify-remote-receive", value: formatDebugCounter("notify-remote-receive")))
+        info.append(DBCustomVariable(name: "notify-remote-launch", value: formatDebugCounter("notify-remote-launch")))
+        info.append(DBCustomVariable(name: "notify-local-wakeup", value: formatDebugCounter("notify-local-wakeup")))
+
         DBDebugToolkit.add(info)
         DBDebugToolkit.showMenu()
     }