Skip to content

Commit

Permalink
Try to recreate task when it returns nil
Browse files Browse the repository at this point in the history
  • Loading branch information
kolyuchiy committed Apr 24, 2014
1 parent c4d6d9a commit 4872bf2
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions AFNetworking/AFURLSessionManager.m
Expand Up @@ -504,6 +504,20 @@ - (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request
{
NSURLSessionUploadTask *uploadTask = [self.session uploadTaskWithRequest:request fromFile:fileURL];

// This may be a bug in iOS. Devforums say that subsequent calls may succeed.
// Let's try to recreate the task.

NSInteger try = 3;
while (! uploadTask && try > 0) {
uploadTask = [self.session uploadTaskWithRequest:request fromFile:fileURL];
try--;
}

if (! uploadTask) {
DVAssert(uploadTask, @"%@ %@ %@ %@ %i", self.session, request, [request URL], fileURL, [[NSFileManager defaultManager] fileExistsAtPath:[fileURL path]]);
return nil;
}

[self addDelegateForUploadTask:uploadTask progress:progress completionHandler:completionHandler];

return uploadTask;
Expand Down

0 comments on commit 4872bf2

Please sign in to comment.