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:
parent
63f5c9706e
commit
87aed00733
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue