Fixed the background task handled in backgroundCleanDisk.

- the background task had no effect, since cleanDisk returns immediately and thereby cancels the background task
 - adding cleanDiskWithCompletionBlock: and modifying backgroundCleanDisk to use this method resolves the issue
This commit is contained in:
Matej Bukovinski 2014-03-24 21:14:21 +01:00
parent 63f5c9706e
commit 87aed00733
1 changed files with 11 additions and 5 deletions

View File

@ -354,6 +354,10 @@ BOOL ImageDataHasPNGPreffix(NSData *data) {
}
- (void)cleanDisk {
[self cleanDiskWithCompletionBlock:nil];
}
- (void)cleanDiskWithCompletionBlock:(void (^)())completionBlock {
dispatch_async(self.ioQueue, ^{
NSURL *diskCacheURL = [NSURL fileURLWithPath:self.diskCachePath isDirectory:YES];
NSArray *resourceKeys = @[NSURLIsDirectoryKey, NSURLContentModificationDateKey, NSURLTotalFileAllocatedSizeKey];
@ -418,6 +422,11 @@ BOOL ImageDataHasPNGPreffix(NSData *data) {
}
}
}
if (completionBlock) {
dispatch_async(dispatch_get_main_queue(), ^{
completionBlock();
});
}
});
}
@ -431,13 +440,10 @@ BOOL ImageDataHasPNGPreffix(NSData *data) {
}];
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Do the work associated with the task, preferably in chunks.
[self cleanDisk];
[self cleanDiskWithCompletionBlock:^{
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
});
}];
}
- (NSUInteger)getSize {