iOS 清除缓存

来源:互联网 发布:redshift渲染器mac 编辑:程序博客网 时间:2024/06/05 17:31

//清除缓存

- (void)clear

{

    dispatch_async(

                   dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0)

                   , ^{

                       NSString *cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES) objectAtIndex:0];

                       

                       NSArray *files = [[NSFileManagerdefaultManager] subpathsAtPath:cachPath];

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

                       for (NSString *pin files) {

                           NSError *error;

                           NSString *path = [cachPathstringByAppendingPathComponent:p];

                           if ([[NSFileManagerdefaultManager] fileExistsAtPath:path]) {

                               [[NSFileManagerdefaultManager] removeItemAtPath:patherror:&error];

                           }

                       }

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


}

-(void)clearCacheSuccess

{

   NSLog(@"清除缓存");

}


0 0
原创粉丝点击