iOS缓存清理
来源:互联网 发布:典型网络暴力事件盘点 编辑:程序博客网 时间:2024/05/17 07:57
.h
#import <Foundation/Foundation.h>#import <UIKit/UIKit.h>@interface CacheManager : NSObject+(CGFloat)getCacheSize;+(void)clearCache;@end
.m
//// CacheManager.m// Buy//// Created by qf on 15/10/17.// Copyright (c) 2015年 Chakery. All rights reserved.//#import "CacheManager.h"@implementation CacheManager//获取缓存大小+(CGFloat)getCacheSize{ __block CGFloat totalSize = 0; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"ImageCache"]; __block NSFileManager *ma = [NSFileManager defaultManager]; NSArray *array = [ma contentsOfDirectoryAtPath:path error:nil]; [array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { NSDictionary *dic = [ma attributesOfItemAtPath:[path stringByAppendingPathComponent:obj] error:nil]; totalSize += [dic fileSize] / 1024.0 / 1024.0; }]; return totalSize;}//清理缓存+(void)clearCache{ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"ImageCache"]; NSFileManager *ma = [NSFileManager defaultManager]; NSArray *array = [ma contentsOfDirectoryAtPath:path error:nil]; [array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [ma removeItemAtPath:[path stringByAppendingPathComponent:obj] error:nil]; }];}@end
0 0
- ios清理缓存
- ios 清理缓存
- iOS 清理缓存
- ios 清理缓存
- iOS 清理缓存代码
- ios 清理缓存
- ios清理缓存
- iOS 清理缓存
- ios 清理缓存
- ios 清理cach缓存
- iOS 清理缓存方法
- iOS APP缓存清理
- iOS 缓存大小 清理
- ios-清理应用缓存
- iOS-Swift-清理缓存
- iOS 清理缓存
- iOS 清理缓存
- iOS 实现缓存清理
- codeforces #334 D. Babaei and Birthday Cake (线段树或者dp+二分)
- Struts2中的相对路径与绝对路径
- 脚本:查看约束信息
- 梯度下降优化算法综述(翻译)
- 基于SpringBoot的通用设备操作接口服务
- iOS缓存清理
- lua eval
- CALayer使用(1)
- Spring Batch 之 Spring Batch 简介(一)
- ffmpeg 解码流程
- 安卓开发中@SuppressLint( NewApi )问题的解决方法
- linux下的open函数中的mode问题
- JS使用document.write输出时换行符的使用
- 实验二:网络测试命令和工具的使用