iOS Cleanup CacheCategory: Object-c basic 2014-06-11 16:28 6490 People read Comments (9) favorite reports
The code to clean up the cache is as follows:
Dispatch_async (
Dispatch_get_global_queue (dispatch_queue_priority_default, 0)
, ^{
NSString *cachpath = [Nssearchpathfordirectoriesindomains (Nscachesdirectory,nsuserdomainmask, YES) objectAtIndex:0] ;
Nsarray *files = [[Nsfilemanager Defaultmanager] subpathsatpath:cachpath];
NSLog (@ "Files:%d", [Files Count]);
For (NSString *p in files) {
Nserror *error;
NSString *path = [Cachpath stringbyappendingpathcomponent:p];
if ([[[Nsfilemanager Defaultmanager] Fileexistsatpath:path]) {
[[Nsfilemanager Defaultmanager] Removeitematpath:path error:&error];
}
}
[Self Performselectoronmainthread: @selector (clearcachesuccess) WithObject:nilwaitUntilDone:YES];});
-(void) clearcachesuccess
{
NSLog (@ "clean success");
}
iOS cleanup cache