| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588 |
- //
- // SettingViewController.m
- // IBOSS
- //
- // Created by guan hong hou on 2018/6/25.
- // Copyright © 2018年 elongtian. All rights reserved.
- //
- #import "SettingNewViewController.h"
- @interface SettingNewViewController (){
- /**
- 缓存文本
- */
- UILabel *lbSize;
- }
- @end
- @implementation SettingNewViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self initUI];
-
- }
- /**
- viewWillAppear
-
- @param animated <#animated description#>
- */
- - (void)viewWillAppear:(BOOL)animated{
- // 修改密码消失
- if(!_clickFlag){
- [self cancelPW];
- }
- [self updateCacheSize:lbSize];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
-
- }
- -(void)initUI{
- self.navigationItem.title = @"设置";
-
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal];
- [button addTarget:self action:@selector(goBack)
- forControlEvents:UIControlEventTouchUpInside];
- button.frame = CGRectMake(0, 0,45,22);
-
- UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
- self.navigationItem.leftBarButtonItem = menuButton;
- _clickFlag = true;
-
- CGFloat titleHeight = 50;
- CGFloat lblx = 20;
- CGFloat fontsize = 14;
- CGFloat valuey = 13;
- CGFloat valueheight = 25;
- CGFloat heightLine =1;
-
- //头布局
- UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 0)];
-
- [self.view addSubview: headView];
- float margin = 5;
- UIView *viewBackgroud;
- CGRect cg = CGRectMake(Screen_Width - lblx - 9,valuey+4,9,15 );
- // //切换用户 —————————
- UIView *vchangeUser = [UIView new];
- vchangeUser.frame=CGRectMake(0,0, Screen_Width, titleHeight);
- [headView addSubview:vchangeUser];
-
- UIImageView *imgview = [UIImageView new];
- imgview.frame=CGRectMake(lblx, valuey+margin, 14, 19);
- [imgview setImage:[UIImage imageNamed:@"setting_change_user"]];
- [vchangeUser addSubview:imgview];
-
- UIButton *btnChangeUser = [UIButton buttonWithType:UIButtonTypeCustom];
- btnChangeUser.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+2*margin, valuey, Screen_Width - CGRectGetMaxX(imgview.frame), valueheight);
- btnChangeUser.titleLabel.font = [UIFont systemFontOfSize:fontsize];
- btnChangeUser.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- [btnChangeUser setTitle:@"切换用户" forState:UIControlStateNormal];
- [btnChangeUser setTitleColor:NavTitleColor forState:UIControlStateNormal];
- [btnChangeUser addTarget:self action:@selector(changeUser) forControlEvents:UIControlEventTouchUpInside];
- [vchangeUser addSubview:btnChangeUser];
- UIImageView *bannerView = [[UIImageView alloc] initWithFrame:cg];
- [bannerView setImage:[UIImage imageNamed:@"setting_right_arrow"]];
- [vchangeUser addSubview:bannerView];
-
- viewBackgroud = [UIView new];
- viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vchangeUser.frame), Screen_Width, heightLine);
- viewBackgroud.backgroundColor = LineBackgroundColor;
- [headView addSubview:viewBackgroud];
-
-
- // 修改密码
- UIView *vchangePw = [UIView new];
- vchangePw.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight);
- [headView addSubview:vchangePw];
-
- imgview = [UIImageView new];
- imgview.frame=CGRectMake(lblx, valuey+margin, 14, 16);
- [imgview setImage:[UIImage imageNamed:@"setting_change_pw"]];
- [vchangePw addSubview:imgview];
-
- UIButton *btnChangePw = [UIButton buttonWithType:UIButtonTypeCustom];
- btnChangePw.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+2*margin, valuey, Screen_Width - CGRectGetMaxX(imgview.frame), valueheight);
- btnChangePw.titleLabel.font = [UIFont systemFontOfSize:fontsize];
- btnChangePw.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- [btnChangePw setTitle:@"修改密码" forState:UIControlStateNormal];
- [btnChangePw setTitleColor:NavTitleColor forState:UIControlStateNormal];
- [btnChangePw addTarget:self action:@selector(changePw) forControlEvents:UIControlEventTouchUpInside];
- [vchangePw addSubview:btnChangePw];
-
- bannerView = [[UIImageView alloc] initWithFrame:cg];
- [bannerView setImage:[UIImage imageNamed:@"setting_right_arrow"]];
- [vchangePw addSubview:bannerView];
-
- viewBackgroud = [UIView new];
- viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vchangePw.frame), Screen_Width,heightLine);
- viewBackgroud.backgroundColor = LineBackgroundColor;
- [headView addSubview:viewBackgroud];
- //清除缓存
- UIView *vClear = [UIView new];
- vClear.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight);
- [headView addSubview:vClear];
-
- imgview = [UIImageView new];
- imgview.frame=CGRectMake(lblx-3, valuey+2, 19, 19);
- [imgview setImage:[UIImage imageNamed:@"icon_clear"]];
- [vClear addSubview:imgview];
-
- UIButton *btnClear = [UIButton buttonWithType:UIButtonTypeCustom];
- btnClear.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+2*margin-2, valuey, Screen_Width - CGRectGetMaxX(imgview.frame), valueheight);
- btnClear.titleLabel.font = [UIFont systemFontOfSize:fontsize];
- btnClear.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- [btnClear setTitle:@"清除缓存" forState:UIControlStateNormal];
- [btnClear setTitleColor:NavTitleColor forState:UIControlStateNormal];
- [btnClear addTarget:self action:@selector(clearData) forControlEvents:UIControlEventTouchUpInside];
- [vClear addSubview:btnClear];
-
- bannerView = [[UIImageView alloc] initWithFrame:cg];
- [bannerView setImage:[UIImage imageNamed:@"setting_right_arrow"]];
- [vClear addSubview:bannerView];
-
-
- UILabel *lbSize = [[UILabel alloc] init];
- [self updateCacheSize:lbSize];
- lbSize.font = [UIFont systemFontOfSize:13];
- lbSize.textColor = [UIColor grayColor];
- [lbSize sizeToFit];
-
- lbSize.frame = CGRectMake(CGRectGetMaxX(bannerView.frame)- CGRectGetWidth(bannerView.frame)-CGRectGetWidth(lbSize.frame)-10, valuey+4, CGRectGetWidth(lbSize.frame), CGRectGetHeight(lbSize.frame));
- [vClear addSubview:lbSize];
- viewBackgroud = [UIView new];
- viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vClear.frame), Screen_Width,heightLine);
- viewBackgroud.backgroundColor = LineBackgroundColor;
- [headView addSubview:viewBackgroud];
-
- // 退出登录
- UIView *vexit = [UIView new];
- vexit.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight);
- [headView addSubview:vexit];
-
- imgview = [UIImageView new];
- imgview.frame=CGRectMake(lblx, valuey + margin, 15, 16);
- [imgview setImage:[UIImage imageNamed:@"setting_exit"]];
- [vexit addSubview:imgview];
-
- UIButton *btnExit= [UIButton buttonWithType:UIButtonTypeCustom];
- btnExit.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+2*margin, valuey, Screen_Width - CGRectGetMaxX(imgview.frame), valueheight);
- btnExit.titleLabel.font = [UIFont systemFontOfSize:fontsize];
- btnExit.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- [btnExit setTitle:@"退出登录" forState:UIControlStateNormal];
- [btnExit setTitleColor:NavTitleColor forState:UIControlStateNormal];
- [btnExit addTarget:self action:@selector(exitApp) forControlEvents:UIControlEventTouchUpInside];
- [vexit addSubview:btnExit];
-
- bannerView = [[UIImageView alloc] initWithFrame:cg];
- [bannerView setImage:[UIImage imageNamed:@"setting_right_arrow"]];
- [vexit addSubview:bannerView];
-
- viewBackgroud = [UIView new];
- viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vexit.frame), Screen_Width,heightLine);
- viewBackgroud.backgroundColor = LineBackgroundColor;
- [headView addSubview:viewBackgroud];
- headView.frame = CGRectMake(0,0, Screen_Width, CGRectGetMaxY(viewBackgroud.frame));
-
-
- }
- #pragma mark - 回调函数
- /**
- 密码修改成功回调成功
-
- @param sender <#sender description#>
- */
- - (void)OnPasswordLoadFinish:(ASIDownManager *)sender{
-
- // 取消进度条
- [self stopLoading];
- // 服务器返回数据
- RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
- // 服务器返回数据状态值
- int iStatus = resultModel.status;
- // 服务器返回数据消息
- NSString *message = resultModel.message;
- // 服务器返回数据状态值正确
- if (iStatus == 0) {
- _clickFlag = true;
- [self showAlertViewText:@"密码修改成功"];
- [_passwordModify removeFromSuperview];
- return;
- }
- else{
- _clickFlag = false;
- [self showAlertViewText:message];
- return;
- }
- }
- /**
- 回调失败
-
- @param sender <#sender description#>
- */
- - (void)OnPasswordLoadFail:(ASIDownManager *)sender{
- [self stopLoading];
- _clickFlag = false;
- [self showAlertViewText:@"密码修改失败"];
- return;
- }
- /**
- 切换用户回调成功
-
- @param sender <#sender description#>
- */
- - (void)onLoadFinish:(ASIDownManager *)sender {
- [self stopLoading];
- // 服务器返回数据转换model
- RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
- // 服务器返回数据状态值
- int iStatus = resultModel.status;
- // 服务器返回数据消息
- NSString *message = resultModel.message;
- // 服务器返回数据状态值正确
- if (iStatus == 0) {
- //个人数据统统滴清除
- kkUserPwdOrinal = @"";
- kkUserPwd = @"";
- kkUserCode = @"";
- kkAccountCode = @"";
- [[UserInfoManager Share]ClearUserData ];
- //退回登录界面
- [Appdelegate changeViewDidLogout];
- }
- else if(iStatus == ActionResultStatusAuthError
- ||iStatus == ActionResultStatusNoLogin
- ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
- [self showReLoginDialog:message];
- }
- else {
- [self showAlertViewText:message];
- // 退回登录界面
- [Appdelegate changeViewDidLogout];
- }
- }
- /**
- 切换用户回调失败
-
- @param sender <#sender description#>
- */
- - (void)onLoadFail:(ASIDownManager *)sender {
- [self stopLoading];
- [self showAlertViewText:@"切换用户失败"];
- }
- /**
- 切换用户
- */
- - (void)changeUser{
-
- __weak typeof (self)weakself = self;
- // 初始化->
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"切换用户" message:@"是否要切换用户吗?" preferredStyle:UIAlertControllerStyleAlert];
- // addAction->
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
- weakself.downManager = [[ASIDownManager alloc] init];
- weakself.downManager.delegate = self;
- weakself.downManager.onRequestSuccess = @selector(onLoadFinish:);
- weakself.downManager.onRequestFail = @selector(onLoadFail:);
-
- [weakself startLoading];
- NSString *urlStr = ServerURL;
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setObject:@"SMDLogout" forKey:@"Action"];
- [dict setObject:kkAccountCode forKey:@"AccountCode"];
- [dict setObject:kkUserCode forKey:@"UserCode"];
- [dict setObject:kkUserPwd forKey:@"UserPassword"];
- [dict setObject:kkSessionKey forKey:@"SessionKey"];
- [weakself.downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
- }];
- // addAction->
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){
-
- }];
- UIColor *cancelColor = [UIColor blackColor];
- UIColor *sureColor = [UIColor redColor];
- [cancelAction setValue:cancelColor forKey:@"titleTextColor"];
- [okAction setValue:sureColor forKey:@"titleTextColor"];
- [alert addAction:okAction];
- [alert addAction:cancelAction];
- // 展示->
- [self presentViewController:alert animated:YES completion:nil];
- }
- /**
- 修改密码
- */
- - (void)changePw{
-
- if(!_clickFlag){
- return;
- }
- _clickFlag = false;
- _passwordModify = [DKPWModifyAlterView alterViewWithTitle:@"密码修改" cancel:@"取消" sure:@"确定"];
- [self.view addSubview:_passwordModify];
- [[_passwordModify sureBt] addTarget:self action:@selector(surePW) forControlEvents:UIControlEventTouchUpInside];
- [[_passwordModify cancelBt] addTarget:self action:@selector(cancelPW) forControlEvents:UIControlEventTouchUpInside];
-
- }
- /**
- 退出app程序
- */
- - (void)exitApp{
- // NSMutableArray *arr = [NSMutableArray array];
- // NSLog(@"%@",arr[10]);
- if(!_clickFlag){
- return;
- }
- //初始化提示框;
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"退出程序" message:@"是否要退出登录吗?" preferredStyle:UIAlertControllerStyleAlert ];
- // addAction->
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
- [self exit];
- }];
-
- // addAction->
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){
-
- }];
-
- UIColor *cancelColor = [UIColor blackColor];
- UIColor *sureColor = [UIColor redColor];
- [cancelAction setValue:cancelColor forKey:@"titleTextColor"];
- [okAction setValue:sureColor forKey:@"titleTextColor"];
- [alert addAction:okAction];
- [alert addAction:cancelAction];
- // 3.显示alertController:presentViewController
- [self presentViewController:alert animated:YES completion:nil];
- }
- /**
- 退出登录
- */
- - (void) exit{
- if([[Util getNetWorkStates] isEqualToString:@"无网络"]){
- exit(0);
- return;
- }
- [self startLoading];
- NSString *urlStr = ServerURL;
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setObject:@"SMDLogout" forKey:@"Action"];
- [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
- [dict setObject:kkUserCode forKey:@"UserCode"];
- [dict setObject:kkUserPwd forKey:@"UserPassword"];
- [dict setObject:kkSessionKey forKey:@"SessionKey"];
-
- self.downManager = [[ASIDownManager alloc] init];
- _downManager.delegate = self;
- _downManager.onRequestSuccess = @selector(onExitFinish:);
- _downManager.onRequestFail = @selector(onExitFail:);
- [_downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
- }
- - (void) onExitFinish:(ASIDownManager *) sender {
- exit(0);
- }
- - (void) onExitFail:(ASIDownManager *) sender {
- exit(0);
- }
- /**
- 确定修改密码
- */
- - (void)surePW{
-
- _originalPassword= _passwordModify.originalPassword.text;
- if(_originalPassword == nil||[_originalPassword isEqualToString:@""]){
- [self showAlertViewText:@"原密码不能为空"];
- return;
- }
- _newsPassword=_passwordModify.nePassword.text;
- if(_newsPassword == nil||[_newsPassword isEqualToString:@""]){
- [self showAlertViewText:@"新密码不能为空"];
- return;
- }
-
- _confirmPassword=_passwordModify.confirmPassword.text;
- if(_confirmPassword == nil||[_confirmPassword isEqualToString:@""]){
- [self showAlertViewText:@"确认密码不能为空"];
- return;
- }
-
- if(![_newsPassword isEqualToString:_confirmPassword]){
- [self showAlertViewText:@"新密码与确认密码不一致"];
- return;
- }
-
- self.downManager = [[ASIDownManager alloc] init];
- [self startLoading];
- self.downManager.delegate = self;
- self.downManager.onRequestSuccess = @selector(OnPasswordLoadFinish:);
- self.downManager.onRequestFail = @selector(OnPasswordLoadFail:);
- NSString *urlStr = ServerURL;
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setObject:@"SaveUserPassWordIphone" forKey:@"Action"];
- [dict setObject:kkAccountCode forKey:@"AccountCode"];
- [dict setObject:kkUserCode forKey:@"UserCode"];
- [dict setObject:kkUserPwd forKey:@"UserPassword"];
- [dict setObject:kkSessionKey forKey:@"SessionKey"];
- [dict setObject:_originalPassword forKey:@"OldUserPassWord"];
- [dict setObject:_newsPassword forKey:@"NewUserPassword"];
- [self.downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
- }
- /**
- 取消修改密码
- */
- - (void)cancelPW{
- _clickFlag = true;
- [_passwordModify removeFromSuperview];
- }
- -(void)clearData{
-
- // // 找到Documents文件夹路径
- // NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
- // NSString *dataFilePath = [documentsPath stringByAppendingPathComponent:@"IBOSSERROR"];
- //
- // NSFileManager *fileManager = [NSFileManager defaultManager];
- //
- // BOOL isDir = NO;
- //
- // // fileExistsAtPath 判断一个文件或目录是否有效,isDirectory判断是否一个目录
- // BOOL existed = [fileManager fileExistsAtPath:dataFilePath isDirectory:&isDir];
- // NSError *error = nil;
- // if ( (isDir == YES && existed == YES) ) {
- // NSArray *fileList = [[NSArray alloc] init];
- // fileList = [fileManager contentsOfDirectoryAtPath:dataFilePath error:&error];
- // NSString* str = fileList.firstObject;
- // NSString *resultStr = [NSString stringWithContentsOfFile:[NSString stringWithFormat:@"%@/%@",dataFilePath,str] encoding:NSUTF8StringEncoding error:nil];
- // NSLog(@"%@",resultStr);
- // }
-
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"清除缓存" message:@"确定要清除所有缓存吗?" preferredStyle:UIAlertControllerStyleAlert ];
- // addAction->
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
- [self deleteFile:IBOSSERROR];
- [self deleteFile:IBOSSIMAGE];
- [self deleteFile:IBOSSSOUND];
- [self updateCacheSize:lbSize];
- }];
-
- // addAction->
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){
-
- }];
-
- UIColor *cancelColor = [UIColor blackColor];
- UIColor *sureColor = [UIColor redColor];
- [cancelAction setValue:cancelColor forKey:@"titleTextColor"];
- [okAction setValue:sureColor forKey:@"titleTextColor"];
- [alert addAction:okAction];
- [alert addAction:cancelAction];
- // 3.显示alertController:presentViewController
- [self presentViewController:alert animated:YES completion:nil];
- }
- /**
- 更新缓存大小
-
- @param lbSize <#lbSize description#>
- */
- - (void)updateCacheSize:(UILabel *) lbSize{
- CGFloat sizeIBOSSERROR = [self folderSizeAtPath: IBOSSERROR];
- CGFloat sizeIBOSSIMAGE = [self folderSizeAtPath: IBOSSIMAGE];
- CGFloat sizeIBOSSSOUND = [self folderSizeAtPath: IBOSSSOUND];
- CGFloat sum = sizeIBOSSERROR+sizeIBOSSIMAGE+sizeIBOSSSOUND;
- if(sum == 0){
- lbSize.hidden = YES;
- }else{
- lbSize.hidden = NO;
- }
-
- lbSize.text = [NSString stringWithFormat:@"约%.2fM",sum];
- [lbSize sizeToFit];
- }
- /**
- 删除Document下文件夹
-
- @param fileName <#fileName description#>
- */
- - (void)deleteFile:(NSString *) fileName{
- NSFileManager* fileManager=[NSFileManager defaultManager];
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
-
- //文件名
- NSString *uniquePath=[[paths objectAtIndex:0] stringByAppendingPathComponent:fileName];
- BOOL blHave=[[NSFileManager defaultManager] fileExistsAtPath:uniquePath];
- if (!blHave) {
- NSLog(@"no have");
- return ;
- }else {
- NSLog(@" have");
- BOOL blDele= [fileManager removeItemAtPath:uniquePath error:nil];
- if (blDele) {
- NSLog(@"dele success");
- }else {
- NSLog(@"dele fail");
- }
-
- }
- }
- //遍历文件夹获得文件夹大小,返回多少M
- - (float )folderSizeAtPath:(NSString*) folderPath{
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
-
- //文件名
- folderPath=[[paths objectAtIndex:0] stringByAppendingPathComponent:folderPath];
-
- NSFileManager* manager = [NSFileManager defaultManager];
-
- if (![manager fileExistsAtPath:folderPath]) return 0;
-
- NSEnumerator *childFilesEnumerator = [[manager subpathsAtPath:folderPath] objectEnumerator];
-
- NSString* fileName;
-
- long long folderSize = 0;
-
- while ((fileName = [childFilesEnumerator nextObject]) != nil){
-
- NSString* fileAbsolutePath = [folderPath stringByAppendingPathComponent:fileName];
-
- folderSize += [self fileSizeAtPath:fileAbsolutePath];
- }
- return folderSize/(1024.0*1024.0);
-
- }
- //单个文件的大小
- - (long long) fileSizeAtPath:(NSString*) filePath{
-
- NSFileManager* manager = [NSFileManager defaultManager];
-
- if ([manager fileExistsAtPath:filePath]){
-
- return [[manager attributesOfItemAtPath:filePath error:nil] fileSize];
- }
-
- return 0;
-
- }
- @end
|