浏览代码

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.maybeStartIo()
         dcContext.maybeNetwork()
         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 {
             if !self.appIsInForeground {
                 self.dcContext.stopIo()
                 self.dcContext.stopIo()
             }
             }
@@ -386,7 +391,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         dcContext.maybeStartIo()
         dcContext.maybeStartIo()
         dcContext.maybeNetwork()
         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 {
             if !self.appIsInForeground {
                 self.dcContext.stopIo()
                 self.dcContext.stopIo()
             }
             }