Clear cache for iOS and cache for ios
-(UITableViewCell *) tableView :( UITableView *) tableViewcellForRowAtIndexPath :( NSIndexPath *) indexPath
{
StaticNSString * identifier = @ "myCell ";
UITableViewCell * cell = [tableViewdequeueReusableCellWithIdentifier: identifier];
If (cell = nil ){
Cell = [[UITableViewCellalloc] initWithStyle: UITableViewCellStyleValue1reuseIdentifier: identifier];
}
Cell. textLabel. text = @ "Clear cache ";
NSString * bundleId = [[[NSBundlemainBundle] infoDictionary] objectForKey: @ "CFBundleIdentifier"];
NSArray * paths = NSSearchPathForDirectoriesInDomains (NSCachesDirectory, NSUserDomainMask, YES );
NSString * path = [[pathsobjectAtIndex: 0] stringByAppendingPathComponent: bundleId];
CGFloatsize = [selffolderSizeAtPath: path];
If (size> 10)
{
If (size: <1000)
{
Cell. detailTextLabel. text = [NSStringstringWithFormat: @ "%. 0fB", size];
} Else if (size <1000*1000 ){
Cell. detailTextLabel. text = [NSStringstringWithFormat: @ "%. 2fKB", size/1000];
} Else {
Cell. detailTextLabel. text = [NSStringstringWithFormat: @ "%. 2fMB", size/1000/1000];
}
} Else {
Cell. detailTextLabel. text = @"";
}
}
-(Void) tableView :( UITableView *) tableViewdidSelectRowAtIndexPath :( NSIndexPath *) indexPath
{
NSString * bundleId = [[[NSBundlemainBundle] infoDictionary] objectForKey: @ "CFBundleIdentifier"];
NSArray * paths = NSSearchPathForDirectoriesInDomains (NSCachesDirectory, NSUserDomainMask, YES );
NSString * path = [[pathsobjectAtIndex: 0] stringByAppendingPathComponent: bundleId];
[[NSFileManagerdefaultManager] removeItemAtPath: patherror: nil];
UIAlertView * alertCache = [[UIAlertViewalloc] initWithTitle: nilmessage: @ "cache clear success" delegate: nilcancelButtonTitle: @ "OK" otherButtonTitles: nil, nil];
[AlertCacheshow];
[TableViewreloadData];
}
Calculate the file size
# Pragmamark-getfilesize
-(Longlong) fileSizeAtPath :( NSString *) filePath {
NSFileManager * manager = [nsfilemanagerdefamanager];
If ([managerfileExistsAtPath: filePath]) {
Return [[managerattributesOfItemAtPath: filePatherror: nil] fileSize];
}
Return 0;
}
-(Float) folderSizeAtPath :( NSString *) folderPath {
NSFileManager * manager = [nsfilemanagerdefamanager];
If (! [ManagerfileExistsAtPath: folderPath]) return 0;
NSEnumerator * childFilesEnumerator = [[managersubpathsAtPath: folderPath] objectEnumerator];
NSString * fileName;
LonglongfolderSize = 0;
While (fileName = [childFilesEnumeratornextObject])! = Nil ){
NSString * fileAbsolutePath = [folderPathstringByAppendingPathComponent: fileName];
FolderSize + = [selffileSizeAtPath: fileAbsolutePath];
}
ReturnfolderSize;
}