//清除缓存
- (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(@"清除失败");
}
}
}
}
网友评论