ios 清理缓存
2016-01-09 11:24
435 查看
一段清理缓存的代码如下:
dispatch_async(
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
, ^{
NSString *cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES) objectAtIndex:0];
NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachPath];
NSLog(@"files :%d",[files count]);
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:nilwaitUntilDone:YES];});
-(void)clearCacheSuccess
{
NSLog(@"清理成功");
}
dispatch_async(
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
, ^{
NSString *cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES) objectAtIndex:0];
NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachPath];
NSLog(@"files :%d",[files count]);
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:nilwaitUntilDone:YES];});
-(void)clearCacheSuccess
{
NSLog(@"清理成功");
}
相关文章推荐
- iOS开发-清理缓存功能的实现
- 【转】ios -- ViewController跳转+传值(方式一)
- ios scrollview
- iOS开发之NSDate
- IOS开发中(null)与<null>的处理
- iOS: 在代码中使用Autolayout (2) – intrinsicContentSize和Content Hugging Priority
- iOS数组排序
- iOS自动布局进阶用法
- iOS8的autolayout和size class
- [示例]NSDictionary编程题-字典的排序应用(iOS7班)
- [示例]NSDictionary编程题-字典的排序应用(iOS6班)
- [示例]NSDictionary编程题-字典的排序应用(iOS5班)
- [示例]NSDictionary编程题-字典的排序应用(iOS4班)
- iOS学习,蓝牙,读取数据方式
- ios中正则表达式的基本使用
- 原创翻译:iOS 应用程序 蓝牙后台运行
- iOS中如何解析 html 的代码
- ios实现简单的查看器
- iOS开发中如何解决TableView中图片延时加载
- iOS 怎样判断两个字符串是否相等