Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
陈高翔
/
DreamSleep-iOS
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 10ab82db
由
cgx
编写于
2022-04-25 20:57:49 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
完成清除缓存功能
1 个父辈
fe09f1ce
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
111 行增加
和
3 行删除
DreamSleep/DreamSleep.xcodeproj/project.pbxproj
DreamSleep/DreamSleep/Network/DsCacheUtils.h
DreamSleep/DreamSleep/Network/DsCacheUtils.m
DreamSleep/DreamSleep/Profile/SystemSet/SetTableView.m
DreamSleep/DreamSleep.xcodeproj/project.pbxproj
查看文件 @
10ab82d
...
...
@@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */
39CC172FB610DA5F29120B56 /* Pods_DreamSleep.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2D11699D88A7A7BDB6168B71 /* Pods_DreamSleep.framework */; settings = {ATTRIBUTES = (Required, ); }; };
D00291892816CD4500C0573B /* DsCacheUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = D00291882816CD4500C0573B /* DsCacheUtils.m */; };
D01814D127FFCBAF00583D4E /* CWCarousel.m in Sources */ = {isa = PBXBuildFile; fileRef = D01814CB27FFCBAF00583D4E /* CWCarousel.m */; };
D01814D227FFCBAF00583D4E /* CWFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = D01814CD27FFCBAF00583D4E /* CWFlowLayout.m */; };
D01814D527FFCCFA00583D4E /* HomeTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = D01814D427FFCCFA00583D4E /* HomeTableView.m */; };
...
...
@@ -126,6 +127,8 @@
2D11699D88A7A7BDB6168B71 /* Pods_DreamSleep.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_DreamSleep.framework; sourceTree = BUILT_PRODUCTS_DIR; };
72E2054B343085AE9898C560 /* Pods-DreamSleep.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DreamSleep.debug.xcconfig"; path = "Target Support Files/Pods-DreamSleep/Pods-DreamSleep.debug.xcconfig"; sourceTree = "<group>"; };
9B4D4A8254C6E2872914AB4D /* Pods-DreamSleep.beta.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DreamSleep.beta.xcconfig"; path = "Target Support Files/Pods-DreamSleep/Pods-DreamSleep.beta.xcconfig"; sourceTree = "<group>"; };
D00291872816CD4500C0573B /* DsCacheUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DsCacheUtils.h; sourceTree = "<group>"; };
D00291882816CD4500C0573B /* DsCacheUtils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DsCacheUtils.m; sourceTree = "<group>"; };
D01814CB27FFCBAF00583D4E /* CWCarousel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CWCarousel.m; sourceTree = "<group>"; };
D01814CC27FFCBAF00583D4E /* CWCarouselHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CWCarouselHeader.h; sourceTree = "<group>"; };
D01814CD27FFCBAF00583D4E /* CWFlowLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CWFlowLayout.m; sourceTree = "<group>"; };
...
...
@@ -421,6 +424,8 @@
D070509928071BAF006D72E1 /* DSNetworkTool.m */,
D0E65FFD2807AC5E006562F2 /* DSProgressHUD.h */,
D0E65FFE2807AC5E006562F2 /* DSProgressHUD.m */,
D00291872816CD4500C0573B /* DsCacheUtils.h */,
D00291882816CD4500C0573B /* DsCacheUtils.m */,
);
path = Network;
sourceTree = "<group>";
...
...
@@ -1086,6 +1091,7 @@
D09D0E9A280D507F008DEDAB /* ProfileAlertView.m in Sources */,
D0506B0C280503A800229278 /* UIButton+Extras.m in Sources */,
D0C50B3F27FD381000DC68F0 /* UIView+Extras.m in Sources */,
D00291892816CD4500C0573B /* DsCacheUtils.m in Sources */,
D07DAC902810546A0067A1BF /* DSImagePickerController.m in Sources */,
D0DF90AE2814390000FC0F64 /* BannerModel.m in Sources */,
D0E65FFF2807AC5E006562F2 /* DSProgressHUD.m in Sources */,
...
...
DreamSleep/DreamSleep/Network/DsCacheUtils.h
0 → 100644
查看文件 @
10ab82d
//
// DsCacheUtils.h
// DreamSleep
//
// Created by peter on 2022/4/25.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/// 读取缓存、清理缓存工具
@interface
DsCacheUtils
:
NSObject
/// 获取缓存大小(以M为单位)
+
(
NSString
*
)
getCacheSize
;
/// 清除缓存
/// @param successBlock successBlock
+
(
void
)
cleanCacheWithSuccess
:(
void
(
^
)(
BOOL
success
))
successBlock
;
@end
NS_ASSUME_NONNULL_END
DreamSleep/DreamSleep/Network/DsCacheUtils.m
0 → 100644
查看文件 @
10ab82d
//
// DsCacheUtils.m
// DreamSleep
//
// Created by peter on 2022/4/25.
//
#import "DsCacheUtils.h"
@implementation
DsCacheUtils
+
(
NSString
*
)
getCacheSize
{
// 得到缓存路径
NSString
*
path
=
NSSearchPathForDirectoriesInDomains
(
NSCachesDirectory
,
NSUserDomainMask
,
YES
).
lastObject
;
NSFileManager
*
manager
=
[
NSFileManager
defaultManager
];
CGFloat
size
=
0
;
// 首先判断是否存在缓存文件
if
([
manager
fileExistsAtPath
:
path
])
{
NSArray
*
childFile
=
[
manager
subpathsAtPath
:
path
];
for
(
NSString
*
fileName
in
childFile
)
{
// 缓存文件绝对路径
NSString
*
absolutPath
=
[
path
stringByAppendingPathComponent
:
fileName
];
size
=
size
+
[
manager
attributesOfItemAtPath
:
absolutPath
error
:
nil
].
fileSize
;
}
// 计算SDWebimage5的缓存和系统缓存总和
// size = size + [[SDImageCache sharedImageCache] totalDiskSize];
}
YYImageCache
*
cache
=
[
YYWebImageManager
sharedManager
].
cache
;
NSInteger
discCache
=
cache
.
diskCache
.
totalCost
;
NSInteger
memoryCache
=
cache
.
memoryCache
.
totalCost
;
size
=
size
+
(
discCache
+
memoryCache
);
if
(
size
<
0
)
{
return
@"0.0M"
;
}
double
returnSize
=
size
/
1024
.
0
/
1024
.
0
;
return
[
NSString
stringWithFormat
:
@"%.1fM"
,
returnSize
];
}
+
(
void
)
cleanCacheWithSuccess
:
(
void
(
^
)(
BOOL
success
))
successBlock
{
// 获取缓存路径
NSString
*
path
=
NSSearchPathForDirectoriesInDomains
(
NSCachesDirectory
,
NSUserDomainMask
,
YES
).
lastObject
;
NSFileManager
*
manager
=
[
NSFileManager
defaultManager
];
// 判断是否存在缓存文件
if
([
manager
fileExistsAtPath
:
path
])
{
NSArray
*
childFile
=
[
manager
subpathsAtPath
:
path
];
// 逐个删除缓存文件
for
(
NSString
*
fileName
in
childFile
)
{
NSString
*
absolutPat
=
[
path
stringByAppendingPathComponent
:
fileName
];
[
manager
removeItemAtPath
:
absolutPat
error
:
nil
];
}
// 清除yywebimage缓存
YYImageCache
*
cache
=
[
YYWebImageManager
sharedManager
].
cache
;
[
cache
.
memoryCache
removeAllObjects
];
[
cache
.
diskCache
removeAllObjects
];
// 删除sdwebimage的缓存
// [[SDWebImageManager sharedManager].imageCache clearWithCacheType:SDImageCacheTypeAll completion:^{
// // 这里是又调用了得到缓存文件大小的方法,是因为不确定是否删除了所有的缓存,所以要计算一遍,展示出来
// if ([[self getCacheSize] isEqualToString:@"0.00M"]) {
// if (successBlock) {
// successBlock(YES);
// }
// [DSProgressHUD showToast:@"清除缓存成功"];
// } else {
// if (successBlock) {
// successBlock(NO);
// }
// [DSProgressHUD showToast:@"清除缓存失败"];
// }
// }];
}
}
@end
DreamSleep/DreamSleep/Profile/SystemSet/SetTableView.m
查看文件 @
10ab82d
...
...
@@ -6,6 +6,7 @@
//
#import "SetTableView.h"
#import "DsCacheUtils.h"
/// 设置自定义数据模型
@interface
SetModel
:
NSObject
...
...
@@ -18,7 +19,8 @@
+
(
NSArray
*
)
getAllSetDatas
{
NSArray
*
titles
=
@[
@"应用版本及升级"
,
@"用户协议"
,
@"隐私政策"
,
@"清除缓存"
];
NSString
*
version
=
[
NSString
stringWithFormat
:
@"当前版本%@"
,
[[[
NSBundle
mainBundle
]
infoDictionary
]
objectForKey
:
@"CFBundleShortVersionString"
]];
NSArray
*
details
=
@[
version
,
@""
,
@""
,
@"10.0M"
];
NSString
*
cacheSize
=
[
DsCacheUtils
getCacheSize
];
NSArray
*
details
=
@[
version
,
@""
,
@""
,
cacheSize
];
NSMutableArray
*
tmpArr
=
[
NSMutableArray
array
];
for
(
int
i
=
0
;
i
<
titles
.
count
;
i
++
)
{
SetModel
*
m
=
[
SetModel
new
];
...
...
@@ -45,7 +47,7 @@
self
.
dk_backgroundColorPicker
=
DKColorPickerWithColors
(
DSWhite
,
CornerViewDarkColor
,
DSWhite
);
self
.
rightIcon
=
[[
UIImageView
alloc
]
initWithImage
:[
UIImage
imageNamed
:
@"moreIcon"
]];
[
self
.
contentView
addSubview
:
self
.
rightIcon
];
self
.
titleLab
=
[
UILabel
dkLabWithFont
:
SysFont
(
15
.
0
)];
[
self
.
contentView
addSubview
:
self
.
titleLab
];
...
...
@@ -242,9 +244,11 @@
[[
UIApplication
sharedApplication
]
openURL
:
url
options
:@{}
completionHandler
:
nil
];
}
}
else
if
(
indexPath
.
row
==
3
)
{
// 清除缓存
[
DsCacheUtils
cleanCacheWithSuccess
:
^
(
BOOL
success
)
{
}];
[
DSProgressHUD
showToast
:
@"清除成功"
];
SetModel
*
m
=
self
.
dataArr
[
indexPath
.
row
];
m
.
detail
=
@"0M"
;
m
.
detail
=
@"0
.0
M"
;
[
tableView
reloadRowsAtIndexPaths
:@[[
NSIndexPath
indexPathForRow
:
indexPath
.
row
inSection
:
0
]]
withRowAnimation
:
UITableViewRowAnimationNone
];
}
else
{
if
(
self
.
setDelegate
&&
[
self
.
setDelegate
respondsToSelector
:
@selector
(
didSelectRowAtIndexPath
:)])
{
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论