ios 清理缓存


- (void)action:(id)sender

{



UIButton * button = sender;

[button setTitle:@"清理完毕" forState:UIControlStateNormal];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);

NSString *path = [paths lastObject];



NSString *str = [NSString stringWithFormat:@"缓存已清除%.1fM", [self folderSizeAtPath:path]];

NSLog(@"%@",str);

NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:path];

for (NSString *p in files) {

NSError *error;

NSString *Path = [path stringByAppendingPathComponent:p];

if ([[NSFileManager defaultManager] fileExistsAtPath:Path]) {

[[NSFileManager defaultManager] removeItemAtPath:Path error:&error];

}

}

posted @ 2016-01-23 10:11  史前巨兽  阅读(163)  评论(0编辑  收藏  举报