清理缓存
来源:互联网 发布:福利app软件 编辑:程序博客网 时间:2024/04/29 18:16
#pragma mark - 清理缓存
- (void)clearCache
{
NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES)firstObject];
NSArray *files = [[NSFileManagerdefaultManager]subpathsAtPath:cachePath];
for (NSString *pin files) {
NSError *error = nil;
NSString *path = [cachePath stringByAppendingPathComponent:p];
if ([[NSFileManagerdefaultManager]fileExistsAtPath:path]) {
[[NSFileManagerdefaultManager]removeItemAtPath:patherror:&error];
}
}
[selfperformSelectorOnMainThread:@selector(clearSuccess)withObject:nilwaitUntilDone:YES];
}
- (void)clearSuccess
{
[self.tableViewreloadSections:[NSIndexSetindexSetWithIndex:0]withRowAnimation:UITableViewRowAnimationNone];
NSString *title = @"恭喜您";
NSString *message = [NSStringstringWithFormat:@"您已成功清理%.1fM缓存",self.cacheData];
UIAlertController *ac = [UIAlertControlleralertControllerWithTitle:title message:messagepreferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancel = [UIAlertActionactionWithTitle:@"确定"style:UIAlertActionStyleCancelhandler:^(UIAlertAction *_Nonnull action) {
NSLog(@"success");
}];
[ac addAction:cancel];
[selfpresentViewController:ac animated:YEScompletion:^{
}];
}
- (CGFloat)cacheData
{
NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES)firstObject];
CGFloat cacheData = [selffolderSizeAtPath:cachePath];
self.cacheData = cacheData;
return cacheData;
}
- (CGFloat)folderSizeAtPath:(NSString *)folderPath
{
NSFileManager *manager = [NSFileManagerdefaultManager];
if (![manager fileExistsAtPath:folderPath]) {
return 0;
}
NSEnumerator *childFilesEnumerator = [[managersubpathsAtPath:folderPath]objectEnumerator];
NSString *fileName = nil;
long long folderSize =0;
while ((fileName = [childFilesEnumerator nextObject]) != nil) {
NSString *fileAbsolutePath = [folderPathstringByAppendingPathComponent:fileName];
folderSize += [self fileSizeAtPath:fileAbsolutePath];
}
return folderSize / (1024.0 *1024.0);
}
- (long long)fileSizeAtPath:(NSString *)filePath
{
NSFileManager *manager = [NSFileManagerdefaultManager];
if ([manager fileExistsAtPath:filePath]) {
return [[managerattributesOfItemAtPath:filePath error:nil]fileSize];
}
return 0;
}
- 缓存清理
- 清理缓存
- 缓存清理
- 清理缓存
- 清理缓存
- 清理缓存
- 清理缓存
- 清理缓存
- 清理缓存
- 清理缓存
- 清理缓存
- 得到缓存及清理缓存
- 页面缓存清理方法
- ajax的缓存清理
- ajax的缓存清理
- asp清理站点缓存
- asp清理站点缓存
- Hibernate清理缓存
- 定制boostrap的导航栏
- nrf51822学习之第一个BLE程序分析
- BZOJ3779 重组病毒
- Hyper-V故障转移群集
- ViewPager设计总体思路
- 清理缓存
- Java-类执行顺序(面向对像编程思想)
- 实习入职第九天:Attempt to call getDuration without a valid mediaplayer
- 关于债券付息的一些日期计算方式
- MongoDB的学习(二)-基本的操作
- 1.读懂tornado的预备知识:什么是epoll
- 关于Pointcut Joinpoint Advice Advisor的理解
- 有参数构造函数的调用
- 数据结构—二叉树层次遍历