IOS清除缓存

 博客出处:  http://blog.csdn.net/daiyelang/article/details/30068351


一段清理缓存的代码如下:

dispatch_async(

dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)

, ^{

                    NSString *cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMaskYESobjectAtIndex:0];

                    

                    NSArray *files = [[NSFileManager defaultManagersubpathsAtPath:cachPath];

                    NSLog(@"files :%d",[files count]);

                    for (NSString *p in files) {

                        NSError *error;

                        NSString *path = [cachPath stringByAppendingPathComponent:p];

                        if ([[NSFileManager defaultManagerfileExistsAtPath:path]) {

                            [[NSFileManager defaultManagerremoveItemAtPath:path error:&error];

                        }

                    }

                    [self performSelectorOnMainThread:@selector(clearCacheSuccess) withObject:nilwaitUntilDone:YES];});


-(void)clearCacheSuccess

{

    NSLog(@"清理成功");

}


你可能感兴趣的:(清除缓存)