清除緩存的代碼如下:// 清理緩存 NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachePath]; NSLog(@"文件數 :%ld",[files count]); for (NSString *p in files) { NSError *error; NSString *path = [cachePath stringByAppendingString:[NSString stringWithFormat:@"/%@",p]]; if([[NSFileManager defaultManager] fileExistsAtPath:path]) { [[NSFileManager defaultManager] removeItemAtPath:path error:&error]; } }在iOS8上可以清理緩存,在iOS9 和 iOS10上無效。
添加回答
舉報
0/150
提交
取消