码迷,mamicode.com
首页 > 其他好文 > 详细

0122 清楚缓存

时间:2016-01-22 21:46:38      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

//start

-(void)clearCashSelf{

    MCLog(@"NSHomeDirectory 沙盒路径----%@",NSHomeDirectory());

    

//    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"清除缓存" message: [NSString stringWithFormat:@"清除%.2fM",fileSizeM] delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"清除本地缓存" message: [NSString stringWithFormat:@"清除%.2fKB",fileSizeM] delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

    alert.tag = 8899;

    [alert show];

    

}

-(float)fileSizeAtPath:(NSString *)path{

    NSFileManager *fileManager=[NSFileManager defaultManager];

    if([fileManager fileExistsAtPath:path]){

        long long size=[fileManager attributesOfItemAtPath:path error:nil].fileSize;

//        return size/1024.0/1024.0;

        return size/1024.0;

 

    }

    return 0;

}

-(float)folderSizeAtPath:(NSString *)path{

    NSFileManager *fileManager=[NSFileManager defaultManager];

    float folderSize;

    if ([fileManager fileExistsAtPath:path]) {

        NSArray *childerFiles=[fileManager subpathsAtPath:path];

        for (NSString *fileName in childerFiles) {

            NSString *absolutePath=[path stringByAppendingPathComponent:fileName];

            folderSize +=[self fileSizeAtPath:absolutePath];

        }

       

        return folderSize;

    }

    return 0;

}

 

-(void)clearCache:(NSString *)path{

    

    NSFileManager *fileManager=[NSFileManager defaultManager];

    if ([fileManager fileExistsAtPath:path]) {

        NSArray *childerFiles=[fileManager subpathsAtPath:path];

        for (NSString *fileName in childerFiles) {

            //如有需要,加入条件,过滤掉不想删除的文件

            NSString *absolutePath=[path stringByAppendingPathComponent:fileName];

            [fileManager removeItemAtPath:absolutePath error:nil];

        }

    }

        [[SDImageCache sharedImageCache] cleanDisk];

}

 

 

 

                [self clearCashSelf];

 

 

 

 

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

            NSString *cachPath = [paths objectAtIndex:0];

            

            [self clearCache:cachPath];

            fileSizeM=0;

//            [TvDataArray removeAllObjects];

            [_TVSatand reloadData];

 

0122 清楚缓存

标签:

原文地址:http://www.cnblogs.com/gzz2016/p/5152028.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!