美文网首页
iOS 清理缓存

iOS 清理缓存

作者: 华楠 | 来源:发表于2016-12-01 15:57 被阅读0次

    不多说,直接上代码,如下:

    - (void)clearCaChe
    {
           NSString *cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
            NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachPath];
            for (NSString *p in files) {
                NSError *error;
                NSString *path = [cachPath stringByAppendingPathComponent:p];
                if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
                    [[NSFileManager defaultManager] removeItemAtPath:path error:&error];
                }
            }
            [self performSelectorOnMainThread:@selector(clearCacheSuccess) withObject:nil waitUntilDone:YES];
    }
    
    
    - (void)clearCacheSuccess
    {
       //清理成功后要做的操作
    }
    

    相关文章

      网友评论

          本文标题:iOS 清理缓存

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