Last active
August 29, 2015 14:13
-
-
Save dlo/9f6ef1754aa56f36a15d to your computer and use it in GitHub Desktop.
Workaround for http://openradar.me/radar?id=5847108682776576
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)cancelLongRunningTasks:(id)sender { | |
NSDate *date = [NSDate date]; | |
void (^CompletionHandler)(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) = ^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) { | |
for (NSURLSessionDownloadTask *task in downloadTasks) { | |
if (task.state == NSURLSessionTaskStateRunning) { | |
NSDate *startDate = self.sessionDownloadTaskStartDates[@(task.taskIdentifier)]; | |
if (startDate) { | |
NSTimeInterval interval = [date timeIntervalSinceDate:startDate]; | |
if (interval > 30) { | |
[task cancel]; | |
} | |
} | |
} | |
} | |
}; | |
[self.session getTasksWithCompletionHandler:CompletionHandler]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment