Преглед изворни кода

always weak reference self in asyncAfter code

cyberta пре 4 година
родитељ
комит
26dc4a1cce
1 измењених фајлова са 12 додато и 2 уклоњено
  1. 12 2
      deltachat-ios/AppDelegate.swift

+ 12 - 2
deltachat-ios/AppDelegate.swift

@@ -119,7 +119,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         dcContext.maybeStartIo()
         dcContext.maybeNetwork()
 
-        DispatchQueue.main.asyncAfter(deadline: .now() + 10) {
+        DispatchQueue.main.asyncAfter(deadline: .now() + 10) { [weak self] in
+            guard let self = self else {
+                completionHandler(.failed)
+                return
+            }
+
             if !self.appIsInForeground {
                 self.dcContext.stopIo()
             }
@@ -386,7 +391,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         dcContext.maybeStartIo()
         dcContext.maybeNetwork()
 
-        DispatchQueue.main.asyncAfter(deadline: .now() + 10) {
+        DispatchQueue.main.asyncAfter(deadline: .now() + 10) { [weak self] in
+            guard let self = self else {
+                completionHandler(.failed)
+                return
+            }
+
             if !self.appIsInForeground {
                 self.dcContext.stopIo()
             }