- (void)clearCachesAction{
//删除本地缓存
NSLog(@"删除本地缓存....");
[self.hudManager With_label:@"正在删除" duration:30];
// 获取Caches目录路径
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachesDir = [paths objectAtIndex:0];
NSString * cookiesDir =[cachesDir stringByReplacingOccurrencesOfString:@"Caches" withString:@"Cookies"];
NSString * temp = NSTemporaryDirectory();
NSLog(@"cachesDir:%@",cachesDir);
NSLog(@"cookiesDir:%@",cookiesDir);
//判断目录是否存在
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL isCachesExist = [fileManager fileExistsAtPath:cachesDir];
BOOL isCookiesExist = [fileManager fileExistsAtPath:cookiesDir];
BOOL isTempExist = [fileManager fileExistsAtPath:cookiesDir];
NSError *error;
//如果存在,则删除目录
if (isCachesExist) {
[fileManager removeItemAtPath:cachesDir error:&error];
if (error) {
NSLog(@"成功删除Caches");
}
else{
NSLog(@"error:%@",error);
}
}
if (isCookiesExist) {
[fileManager removeItemAtPath:cookiesDir error:&error];
if (error) {
NSLog(@"成功删除Cookies");
}
else{
NSLog(@"error:%@",error);
}
}
if (isTempExist) {
[fileManager removeItemAtPath:temp error:&error];
}
[self.hudManager hide];
[MBProgressHUDManager showTextIncenter:@"成功删除缓存"];
}