Because the project needs to calculate the size of the cache file in the application and cleanup work, do a small module to share, casually say that buy apples or choose a 16g or more so mom will not worry about your memory is not enough oh!
clear Local cache file
+ (void) Clearcachefile
{
nsstring *cachpath = [nssearchpathfordirectoriesindomains(nscachesdirectory, Nsuserdomainmask, YES) objectatindex:0];
nsarray *files = [[nsfilemanager defaultmanager] subpathsatpath: Cachpath];
for (nsstring *filename in files)
{
nserror *error;
nsstring *path = [Cachpath stringbyappendingpathcomponent: fileName];
if ([[nsfilemanager defaultmanager] fileexistsatpath:p Ath])
{
[[nsfilemanager defaultmanager] removeitematpath:p ath error:&error];
}
}
}
calculate local cache file size
+ (double) getcachefilesize
{
nsfilemanager *filemanager = [nsfilemanager defaultmanager];
double fileSize = 0.0;
nsstring *cachpath = [nssearchpathfordirectoriesindomains(nscachesdirectory, Nsuserdomainmask, YES) objectatindex:0];
nsarray *files = [FileManager subpathsatpath: Cachpath];
for (nsstring *filename in files)
{
nsstring *path = [Cachpath stringbyappendingpathcomponent: fileName];
if ([FileManager fileexistsatpath:p Ath])
{
nsdictionary *fileattributes = [FileManager attributesofitematpath:p ath error: Nil];
FileSize + = (double) ([FileAttributes fileSize]);
}
}
return fileSize;
}
IOS get local cache file size and erase