Skip to content

Commit 87aed00

Browse files
committed
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
1 parent 63f5c97 commit 87aed00

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

SDWebImage/SDImageCache.m

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,10 @@ - (void)clearDiskOnCompletion:(void (^)())completion
354354
}
355355

356356
- (void)cleanDisk {
357+
[self cleanDiskWithCompletionBlock:nil];
358+
}
359+
360+
- (void)cleanDiskWithCompletionBlock:(void (^)())completionBlock {
357361
dispatch_async(self.ioQueue, ^{
358362
NSURL *diskCacheURL = [NSURL fileURLWithPath:self.diskCachePath isDirectory:YES];
359363
NSArray *resourceKeys = @[NSURLIsDirectoryKey, NSURLContentModificationDateKey, NSURLTotalFileAllocatedSizeKey];
@@ -418,6 +422,11 @@ - (void)cleanDisk {
418422
}
419423
}
420424
}
425+
if (completionBlock) {
426+
dispatch_async(dispatch_get_main_queue(), ^{
427+
completionBlock();
428+
});
429+
}
421430
});
422431
}
423432

@@ -431,13 +440,10 @@ - (void)backgroundCleanDisk {
431440
}];
432441

433442
// Start the long-running task and return immediately.
434-
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
435-
// Do the work associated with the task, preferably in chunks.
436-
[self cleanDisk];
437-
443+
[self cleanDiskWithCompletionBlock:^{
438444
[application endBackgroundTask:bgTask];
439445
bgTask = UIBackgroundTaskInvalid;
440-
});
446+
}];
441447
}
442448

443449
- (NSUInteger)getSize {

0 commit comments

Comments
 (0)