Ver código fonte

call notify-completion-handler more accurate

before, we were always calling the notify-completion-handlers
with .newData - not sure in detail how apple handles throttling,
however, i would notify less often when i know,
that there were just new data and eg. battery is low
(there are also some so posts pointing in that direction).

one could also agrue in the other direction, however,
i would also ignore return values from apps _always_ saying the same.

not sure, what exactly apple does here,
there is few documentation about that (or i did not found them)
maybe it is better to be just honest :)

nb: we could refactor the two entry points to one
function, however, now, during testing and tweaking,
it is better to have that separated.

also, at some point,
it would be useful to know better from the core when a fetch is completed,
however, until then, the "10 seconds" is the best we have :)
B. Petersen 4 anos atrás
pai
commit
b8ac0f267e
1 arquivos alterados com 4 adições e 2 exclusões
  1. 4 2
      deltachat-ios/AppDelegate.swift

+ 4 - 2
deltachat-ios/AppDelegate.swift

@@ -115,6 +115,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     func application(_: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
         logger.info("---- background-fetch ----")
         increaseDebugCounter("notify-local-wakeup")
+        let oldFresh = DcContext.shared.getFreshMessages().count
 
         dcContext.maybeStartIo()
         dcContext.maybeNetwork()
@@ -123,7 +124,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
             if !self.appIsInForeground {
                 self.dcContext.stopIo()
             }
-            completionHandler(.newData)
+            completionHandler(DcContext.shared.getFreshMessages().count > oldFresh ? .newData : .noData)
         }
     }
 
@@ -382,6 +383,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
         logger.verbose("Notifications: didReceiveRemoteNotification \(userInfo)")
         increaseDebugCounter("notify-remote-receive")
+        let oldFresh = DcContext.shared.getFreshMessages().count
 
         dcContext.maybeStartIo()
         dcContext.maybeNetwork()
@@ -390,7 +392,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
             if !self.appIsInForeground {
                 self.dcContext.stopIo()
             }
-            completionHandler(.newData)
+            completionHandler(DcContext.shared.getFreshMessages().count > oldFresh ? .newData : .noData)
         }
     }