清理缓存

作者: 静花寒 | 来源:发表于2015-12-26 17:51 被阅读178次

//清除缓存

- (void)removeCache

{

//===============清除缓存==============

//获取路径

NSString*cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES)objectAtIndex:0];

//返回路径中的文件数组

NSArray*files = [[NSFileManagerdefaultManager]subpathsAtPath:cachePath];

NSLog(@"文件数:%ld",[filescount]);

for(NSString*pinfiles)

{

NSError*error;

NSString*path = [cachePathstringByAppendingString:[NSStringstringWithFormat:@"/%@",p]];

if([[NSFileManagerdefaultManager]fileExistsAtPath:path])

{

BOOLisRemove = [[NSFileManagerdefaultManager]removeItemAtPath:patherror:&error];

if(isRemove) {

NSLog(@"清除成功");

//这里发送一个通知给外界,外界接收通知,可以做一些操作(比如UIAlertViewController)

[[NSNotificationCenterdefaultCenter]postNotificationName:@"clear"object:nil];

}else{

NSLog(@"清除失败");

}

}

}

}

相关文章

网友评论

    本文标题:清理缓存

    本文链接:https://www.haomeiwen.com/subject/fdlbhttx.html