Explorar o código

[Issue #1703] Checking for non-nil delegate in URLSession:didCompleteWithError:

Signed-off-by: Mattt Thompson <m@mattt.me>
Kaom Te %!s(int64=11) %!d(string=hai) anos
pai
achega
e1beaa3fa7
Modificáronse 1 ficheiros con 9 adicións e 5 borrados
  1. 9 5
      AFNetworking/AFURLSessionManager.m

+ 9 - 5
AFNetworking/AFURLSessionManager.m

@@ -740,13 +740,17 @@ totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend
 didCompleteWithError:(NSError *)error
 {
     AFURLSessionManagerTaskDelegate *delegate = [self delegateForTask:task];
-    [delegate URLSession:session task:task didCompleteWithError:error];
 
-    if (self.taskDidComplete) {
-        self.taskDidComplete(session, task, error);
-    }
+    // delegate may be nil when completing a task in the background
+    if (delegate) {
+        [delegate URLSession:session task:task didCompleteWithError:error];
 
-    [self removeDelegateForTask:task];
+        if (self.taskDidComplete) {
+            self.taskDidComplete(session, task, error);
+        }
+
+        [self removeDelegateForTask:task];
+    }
 
     [task removeObserver:self forKeyPath:@"state" context:AFTaskStateChangedContext];
 }