Added background clean disk to UIApplicationDidEnterBackgroundNotification #306
This commit is contained in:
parent
282e817919
commit
fb196ead9b
|
@ -71,6 +71,11 @@ static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week
|
|||
selector:@selector(cleanDisk)
|
||||
name:UIApplicationWillTerminateNotification
|
||||
object:nil];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(backgroundCleanDisk)
|
||||
name:UIApplicationDidEnterBackgroundNotification
|
||||
object:nil];
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -402,7 +407,29 @@ static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week
|
|||
});
|
||||
}
|
||||
|
||||
-(unsigned long long)getSize
|
||||
- (void)backgroundCleanDisk
|
||||
{
|
||||
UIApplication *application = [UIApplication sharedApplication];
|
||||
__block UIBackgroundTaskIdentifier bgTask = [application beginBackgroundTaskWithExpirationHandler:^
|
||||
{
|
||||
// Clean up any unfinished task business by marking where you
|
||||
// stopped or ending the task outright.
|
||||
[application endBackgroundTask:bgTask];
|
||||
bgTask = UIBackgroundTaskInvalid;
|
||||
}];
|
||||
|
||||
// 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];
|
||||
|
||||
[application endBackgroundTask:bgTask];
|
||||
bgTask = UIBackgroundTaskInvalid;
|
||||
});
|
||||
}
|
||||
|
||||
- (unsigned long long)getSize
|
||||
{
|
||||
unsigned long long size = 0;
|
||||
NSDirectoryEnumerator *fileEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:self.diskCachePath];
|
||||
|
|
Loading…
Reference in New Issue