SettingNewViewController.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. //
  2. // SettingViewController.m
  3. // IBOSS
  4. //
  5. // Created by guan hong hou on 2018/6/25.
  6. // Copyright © 2018年 elongtian. All rights reserved.
  7. //
  8. #import "SettingNewViewController.h"
  9. @interface SettingNewViewController (){
  10. /**
  11. 缓存文本
  12. */
  13. UILabel *lbSize;
  14. }
  15. @end
  16. @implementation SettingNewViewController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. [self initUI];
  20. }
  21. /**
  22. viewWillAppear
  23. @param animated <#animated description#>
  24. */
  25. - (void)viewWillAppear:(BOOL)animated{
  26. // 修改密码消失
  27. if(!_clickFlag){
  28. [self cancelPW];
  29. }
  30. [self updateCacheSize:lbSize];
  31. }
  32. - (void)didReceiveMemoryWarning {
  33. [super didReceiveMemoryWarning];
  34. }
  35. -(void)initUI{
  36. self.navigationItem.title = @"设置";
  37. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  38. [button setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal];
  39. [button addTarget:self action:@selector(goBack)
  40. forControlEvents:UIControlEventTouchUpInside];
  41. button.frame = CGRectMake(0, 0,45,22);
  42. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  43. self.navigationItem.leftBarButtonItem = menuButton;
  44. _clickFlag = true;
  45. CGFloat titleHeight = 50;
  46. CGFloat lblx = 20;
  47. CGFloat fontsize = 14;
  48. CGFloat valuey = 13;
  49. CGFloat valueheight = 25;
  50. CGFloat heightLine =1;
  51. //头布局
  52. UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 0)];
  53. [self.view addSubview: headView];
  54. float margin = 5;
  55. UIView *viewBackgroud;
  56. CGRect cg = CGRectMake(Screen_Width - lblx - 9,valuey+4,9,15 );
  57. // //切换用户 —————————
  58. UIView *vchangeUser = [UIView new];
  59. vchangeUser.frame=CGRectMake(0,0, Screen_Width, titleHeight);
  60. [headView addSubview:vchangeUser];
  61. UIImageView *imgview = [UIImageView new];
  62. imgview.frame=CGRectMake(lblx, valuey+margin, 14, 19);
  63. [imgview setImage:[UIImage imageNamed:@"setting_change_user"]];
  64. [vchangeUser addSubview:imgview];
  65. UIButton *btnChangeUser = [UIButton buttonWithType:UIButtonTypeCustom];
  66. btnChangeUser.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+2*margin, valuey, Screen_Width - CGRectGetMaxX(imgview.frame), valueheight);
  67. btnChangeUser.titleLabel.font = [UIFont systemFontOfSize:fontsize];
  68. btnChangeUser.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  69. [btnChangeUser setTitle:@"切换用户" forState:UIControlStateNormal];
  70. [btnChangeUser setTitleColor:NavTitleColor forState:UIControlStateNormal];
  71. [btnChangeUser addTarget:self action:@selector(changeUser) forControlEvents:UIControlEventTouchUpInside];
  72. [vchangeUser addSubview:btnChangeUser];
  73. UIImageView *bannerView = [[UIImageView alloc] initWithFrame:cg];
  74. [bannerView setImage:[UIImage imageNamed:@"setting_right_arrow"]];
  75. [vchangeUser addSubview:bannerView];
  76. viewBackgroud = [UIView new];
  77. viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vchangeUser.frame), Screen_Width, heightLine);
  78. viewBackgroud.backgroundColor = LineBackgroundColor;
  79. [headView addSubview:viewBackgroud];
  80. // 修改密码
  81. UIView *vchangePw = [UIView new];
  82. vchangePw.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight);
  83. [headView addSubview:vchangePw];
  84. imgview = [UIImageView new];
  85. imgview.frame=CGRectMake(lblx, valuey+margin, 14, 16);
  86. [imgview setImage:[UIImage imageNamed:@"setting_change_pw"]];
  87. [vchangePw addSubview:imgview];
  88. UIButton *btnChangePw = [UIButton buttonWithType:UIButtonTypeCustom];
  89. btnChangePw.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+2*margin, valuey, Screen_Width - CGRectGetMaxX(imgview.frame), valueheight);
  90. btnChangePw.titleLabel.font = [UIFont systemFontOfSize:fontsize];
  91. btnChangePw.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  92. [btnChangePw setTitle:@"修改密码" forState:UIControlStateNormal];
  93. [btnChangePw setTitleColor:NavTitleColor forState:UIControlStateNormal];
  94. [btnChangePw addTarget:self action:@selector(changePw) forControlEvents:UIControlEventTouchUpInside];
  95. [vchangePw addSubview:btnChangePw];
  96. bannerView = [[UIImageView alloc] initWithFrame:cg];
  97. [bannerView setImage:[UIImage imageNamed:@"setting_right_arrow"]];
  98. [vchangePw addSubview:bannerView];
  99. viewBackgroud = [UIView new];
  100. viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vchangePw.frame), Screen_Width,heightLine);
  101. viewBackgroud.backgroundColor = LineBackgroundColor;
  102. [headView addSubview:viewBackgroud];
  103. //清除缓存
  104. UIView *vClear = [UIView new];
  105. vClear.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight);
  106. [headView addSubview:vClear];
  107. imgview = [UIImageView new];
  108. imgview.frame=CGRectMake(lblx-3, valuey+2, 19, 19);
  109. [imgview setImage:[UIImage imageNamed:@"icon_clear"]];
  110. [vClear addSubview:imgview];
  111. UIButton *btnClear = [UIButton buttonWithType:UIButtonTypeCustom];
  112. btnClear.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+2*margin-2, valuey, Screen_Width - CGRectGetMaxX(imgview.frame), valueheight);
  113. btnClear.titleLabel.font = [UIFont systemFontOfSize:fontsize];
  114. btnClear.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  115. [btnClear setTitle:@"清除缓存" forState:UIControlStateNormal];
  116. [btnClear setTitleColor:NavTitleColor forState:UIControlStateNormal];
  117. [btnClear addTarget:self action:@selector(clearData) forControlEvents:UIControlEventTouchUpInside];
  118. [vClear addSubview:btnClear];
  119. bannerView = [[UIImageView alloc] initWithFrame:cg];
  120. [bannerView setImage:[UIImage imageNamed:@"setting_right_arrow"]];
  121. [vClear addSubview:bannerView];
  122. UILabel *lbSize = [[UILabel alloc] init];
  123. [self updateCacheSize:lbSize];
  124. lbSize.font = [UIFont systemFontOfSize:13];
  125. lbSize.textColor = [UIColor grayColor];
  126. [lbSize sizeToFit];
  127. lbSize.frame = CGRectMake(CGRectGetMaxX(bannerView.frame)- CGRectGetWidth(bannerView.frame)-CGRectGetWidth(lbSize.frame)-10, valuey+4, CGRectGetWidth(lbSize.frame), CGRectGetHeight(lbSize.frame));
  128. [vClear addSubview:lbSize];
  129. viewBackgroud = [UIView new];
  130. viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vClear.frame), Screen_Width,heightLine);
  131. viewBackgroud.backgroundColor = LineBackgroundColor;
  132. [headView addSubview:viewBackgroud];
  133. // 退出登录
  134. UIView *vexit = [UIView new];
  135. vexit.frame=CGRectMake(0, CGRectGetMaxY(viewBackgroud.frame), Screen_Width, titleHeight);
  136. [headView addSubview:vexit];
  137. imgview = [UIImageView new];
  138. imgview.frame=CGRectMake(lblx, valuey + margin, 15, 16);
  139. [imgview setImage:[UIImage imageNamed:@"setting_exit"]];
  140. [vexit addSubview:imgview];
  141. UIButton *btnExit= [UIButton buttonWithType:UIButtonTypeCustom];
  142. btnExit.frame=CGRectMake(CGRectGetMaxX(imgview.frame)+2*margin, valuey, Screen_Width - CGRectGetMaxX(imgview.frame), valueheight);
  143. btnExit.titleLabel.font = [UIFont systemFontOfSize:fontsize];
  144. btnExit.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  145. [btnExit setTitle:@"退出登录" forState:UIControlStateNormal];
  146. [btnExit setTitleColor:NavTitleColor forState:UIControlStateNormal];
  147. [btnExit addTarget:self action:@selector(exitApp) forControlEvents:UIControlEventTouchUpInside];
  148. [vexit addSubview:btnExit];
  149. bannerView = [[UIImageView alloc] initWithFrame:cg];
  150. [bannerView setImage:[UIImage imageNamed:@"setting_right_arrow"]];
  151. [vexit addSubview:bannerView];
  152. viewBackgroud = [UIView new];
  153. viewBackgroud.frame = CGRectMake(0, CGRectGetMaxY(vexit.frame), Screen_Width,heightLine);
  154. viewBackgroud.backgroundColor = LineBackgroundColor;
  155. [headView addSubview:viewBackgroud];
  156. headView.frame = CGRectMake(0,0, Screen_Width, CGRectGetMaxY(viewBackgroud.frame));
  157. }
  158. #pragma mark - 回调函数
  159. /**
  160. 密码修改成功回调成功
  161. @param sender <#sender description#>
  162. */
  163. - (void)OnPasswordLoadFinish:(ASIDownManager *)sender{
  164. // 取消进度条
  165. [self stopLoading];
  166. // 服务器返回数据
  167. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  168. // 服务器返回数据状态值
  169. int iStatus = resultModel.status;
  170. // 服务器返回数据消息
  171. NSString *message = resultModel.message;
  172. // 服务器返回数据状态值正确
  173. if (iStatus == 0) {
  174. _clickFlag = true;
  175. [self showAlertViewText:@"密码修改成功"];
  176. [_passwordModify removeFromSuperview];
  177. return;
  178. }
  179. else{
  180. _clickFlag = false;
  181. [self showAlertViewText:message];
  182. return;
  183. }
  184. }
  185. /**
  186. 回调失败
  187. @param sender <#sender description#>
  188. */
  189. - (void)OnPasswordLoadFail:(ASIDownManager *)sender{
  190. [self stopLoading];
  191. _clickFlag = false;
  192. [self showAlertViewText:@"密码修改失败"];
  193. return;
  194. }
  195. /**
  196. 切换用户回调成功
  197. @param sender <#sender description#>
  198. */
  199. - (void)onLoadFinish:(ASIDownManager *)sender {
  200. [self stopLoading];
  201. // 服务器返回数据转换model
  202. RequestResultModel *resultModel = [RequestResultModel dk_modelWithJSON:sender.mWebStr];
  203. // 服务器返回数据状态值
  204. int iStatus = resultModel.status;
  205. // 服务器返回数据消息
  206. NSString *message = resultModel.message;
  207. // 服务器返回数据状态值正确
  208. if (iStatus == 0) {
  209. //个人数据统统滴清除
  210. kkUserPwdOrinal = @"";
  211. kkUserPwd = @"";
  212. kkUserCode = @"";
  213. kkAccountCode = @"";
  214. [[UserInfoManager Share]ClearUserData ];
  215. //退回登录界面
  216. [Appdelegate changeViewDidLogout];
  217. }
  218. else if(iStatus == ActionResultStatusAuthError
  219. ||iStatus == ActionResultStatusNoLogin
  220. ||iStatus == ActionResultStatusLogined||iStatus==ActionResultSessionOverdue){
  221. [self showReLoginDialog:message];
  222. }
  223. else {
  224. [self showAlertViewText:message];
  225. // 退回登录界面
  226. [Appdelegate changeViewDidLogout];
  227. }
  228. }
  229. /**
  230. 切换用户回调失败
  231. @param sender <#sender description#>
  232. */
  233. - (void)onLoadFail:(ASIDownManager *)sender {
  234. [self stopLoading];
  235. [self showAlertViewText:@"切换用户失败"];
  236. }
  237. /**
  238. 切换用户
  239. */
  240. - (void)changeUser{
  241. __weak typeof (self)weakself = self;
  242. // 初始化->
  243. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"切换用户" message:@"是否要切换用户吗?" preferredStyle:UIAlertControllerStyleAlert];
  244. // addAction->
  245. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
  246. weakself.downManager = [[ASIDownManager alloc] init];
  247. weakself.downManager.delegate = self;
  248. weakself.downManager.onRequestSuccess = @selector(onLoadFinish:);
  249. weakself.downManager.onRequestFail = @selector(onLoadFail:);
  250. [weakself startLoading];
  251. NSString *urlStr = ServerURL;
  252. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  253. [dict setObject:@"SMDLogout" forKey:@"Action"];
  254. [dict setObject:kkAccountCode forKey:@"AccountCode"];
  255. [dict setObject:kkUserCode forKey:@"UserCode"];
  256. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  257. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  258. [weakself.downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  259. }];
  260. // addAction->
  261. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){
  262. }];
  263. UIColor *cancelColor = [UIColor blackColor];
  264. UIColor *sureColor = [UIColor redColor];
  265. [cancelAction setValue:cancelColor forKey:@"titleTextColor"];
  266. [okAction setValue:sureColor forKey:@"titleTextColor"];
  267. [alert addAction:okAction];
  268. [alert addAction:cancelAction];
  269. // 展示->
  270. [self presentViewController:alert animated:YES completion:nil];
  271. }
  272. /**
  273. 修改密码
  274. */
  275. - (void)changePw{
  276. if(!_clickFlag){
  277. return;
  278. }
  279. _clickFlag = false;
  280. _passwordModify = [DKPWModifyAlterView alterViewWithTitle:@"密码修改" cancel:@"取消" sure:@"确定"];
  281. [self.view addSubview:_passwordModify];
  282. [[_passwordModify sureBt] addTarget:self action:@selector(surePW) forControlEvents:UIControlEventTouchUpInside];
  283. [[_passwordModify cancelBt] addTarget:self action:@selector(cancelPW) forControlEvents:UIControlEventTouchUpInside];
  284. }
  285. /**
  286. 退出app程序
  287. */
  288. - (void)exitApp{
  289. // NSMutableArray *arr = [NSMutableArray array];
  290. // NSLog(@"%@",arr[10]);
  291. if(!_clickFlag){
  292. return;
  293. }
  294. //初始化提示框;
  295. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"退出程序" message:@"是否要退出登录吗?" preferredStyle:UIAlertControllerStyleAlert ];
  296. // addAction->
  297. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
  298. [self exit];
  299. }];
  300. // addAction->
  301. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){
  302. }];
  303. UIColor *cancelColor = [UIColor blackColor];
  304. UIColor *sureColor = [UIColor redColor];
  305. [cancelAction setValue:cancelColor forKey:@"titleTextColor"];
  306. [okAction setValue:sureColor forKey:@"titleTextColor"];
  307. [alert addAction:okAction];
  308. [alert addAction:cancelAction];
  309. // 3.显示alertController:presentViewController
  310. [self presentViewController:alert animated:YES completion:nil];
  311. }
  312. /**
  313. 退出登录
  314. */
  315. - (void) exit{
  316. if([[Util getNetWorkStates] isEqualToString:@"无网络"]){
  317. exit(0);
  318. return;
  319. }
  320. [self startLoading];
  321. NSString *urlStr = ServerURL;
  322. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  323. [dict setObject:@"SMDLogout" forKey:@"Action"];
  324. [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
  325. [dict setObject:kkUserCode forKey:@"UserCode"];
  326. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  327. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  328. self.downManager = [[ASIDownManager alloc] init];
  329. _downManager.delegate = self;
  330. _downManager.onRequestSuccess = @selector(onExitFinish:);
  331. _downManager.onRequestFail = @selector(onExitFail:);
  332. [_downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  333. }
  334. - (void) onExitFinish:(ASIDownManager *) sender {
  335. exit(0);
  336. }
  337. - (void) onExitFail:(ASIDownManager *) sender {
  338. exit(0);
  339. }
  340. /**
  341. 确定修改密码
  342. */
  343. - (void)surePW{
  344. _originalPassword= _passwordModify.originalPassword.text;
  345. if(_originalPassword == nil||[_originalPassword isEqualToString:@""]){
  346. [self showAlertViewText:@"原密码不能为空"];
  347. return;
  348. }
  349. _newsPassword=_passwordModify.nePassword.text;
  350. if(_newsPassword == nil||[_newsPassword isEqualToString:@""]){
  351. [self showAlertViewText:@"新密码不能为空"];
  352. return;
  353. }
  354. _confirmPassword=_passwordModify.confirmPassword.text;
  355. if(_confirmPassword == nil||[_confirmPassword isEqualToString:@""]){
  356. [self showAlertViewText:@"确认密码不能为空"];
  357. return;
  358. }
  359. if(![_newsPassword isEqualToString:_confirmPassword]){
  360. [self showAlertViewText:@"新密码与确认密码不一致"];
  361. return;
  362. }
  363. self.downManager = [[ASIDownManager alloc] init];
  364. [self startLoading];
  365. self.downManager.delegate = self;
  366. self.downManager.onRequestSuccess = @selector(OnPasswordLoadFinish:);
  367. self.downManager.onRequestFail = @selector(OnPasswordLoadFail:);
  368. NSString *urlStr = ServerURL;
  369. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  370. [dict setObject:@"SaveUserPassWordIphone" forKey:@"Action"];
  371. [dict setObject:kkAccountCode forKey:@"AccountCode"];
  372. [dict setObject:kkUserCode forKey:@"UserCode"];
  373. [dict setObject:kkUserPwd forKey:@"UserPassword"];
  374. [dict setObject:kkSessionKey forKey:@"SessionKey"];
  375. [dict setObject:_originalPassword forKey:@"OldUserPassWord"];
  376. [dict setObject:_newsPassword forKey:@"NewUserPassword"];
  377. [self.downManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
  378. }
  379. /**
  380. 取消修改密码
  381. */
  382. - (void)cancelPW{
  383. _clickFlag = true;
  384. [_passwordModify removeFromSuperview];
  385. }
  386. -(void)clearData{
  387. // // 找到Documents文件夹路径
  388. // NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
  389. // NSString *dataFilePath = [documentsPath stringByAppendingPathComponent:@"IBOSSERROR"];
  390. //
  391. // NSFileManager *fileManager = [NSFileManager defaultManager];
  392. //
  393. // BOOL isDir = NO;
  394. //
  395. // // fileExistsAtPath 判断一个文件或目录是否有效,isDirectory判断是否一个目录
  396. // BOOL existed = [fileManager fileExistsAtPath:dataFilePath isDirectory:&isDir];
  397. // NSError *error = nil;
  398. // if ( (isDir == YES && existed == YES) ) {
  399. // NSArray *fileList = [[NSArray alloc] init];
  400. // fileList = [fileManager contentsOfDirectoryAtPath:dataFilePath error:&error];
  401. // NSString* str = fileList.firstObject;
  402. // NSString *resultStr = [NSString stringWithContentsOfFile:[NSString stringWithFormat:@"%@/%@",dataFilePath,str] encoding:NSUTF8StringEncoding error:nil];
  403. // NSLog(@"%@",resultStr);
  404. // }
  405. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"清除缓存" message:@"确定要清除所有缓存吗?" preferredStyle:UIAlertControllerStyleAlert ];
  406. // addAction->
  407. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
  408. [self deleteFile:IBOSSERROR];
  409. [self deleteFile:IBOSSIMAGE];
  410. [self deleteFile:IBOSSSOUND];
  411. [self updateCacheSize:lbSize];
  412. }];
  413. // addAction->
  414. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){
  415. }];
  416. UIColor *cancelColor = [UIColor blackColor];
  417. UIColor *sureColor = [UIColor redColor];
  418. [cancelAction setValue:cancelColor forKey:@"titleTextColor"];
  419. [okAction setValue:sureColor forKey:@"titleTextColor"];
  420. [alert addAction:okAction];
  421. [alert addAction:cancelAction];
  422. // 3.显示alertController:presentViewController
  423. [self presentViewController:alert animated:YES completion:nil];
  424. }
  425. /**
  426. 更新缓存大小
  427. @param lbSize <#lbSize description#>
  428. */
  429. - (void)updateCacheSize:(UILabel *) lbSize{
  430. CGFloat sizeIBOSSERROR = [self folderSizeAtPath: IBOSSERROR];
  431. CGFloat sizeIBOSSIMAGE = [self folderSizeAtPath: IBOSSIMAGE];
  432. CGFloat sizeIBOSSSOUND = [self folderSizeAtPath: IBOSSSOUND];
  433. CGFloat sum = sizeIBOSSERROR+sizeIBOSSIMAGE+sizeIBOSSSOUND;
  434. if(sum == 0){
  435. lbSize.hidden = YES;
  436. }else{
  437. lbSize.hidden = NO;
  438. }
  439. lbSize.text = [NSString stringWithFormat:@"约%.2fM",sum];
  440. [lbSize sizeToFit];
  441. }
  442. /**
  443. 删除Document下文件夹
  444. @param fileName <#fileName description#>
  445. */
  446. - (void)deleteFile:(NSString *) fileName{
  447. NSFileManager* fileManager=[NSFileManager defaultManager];
  448. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
  449. //文件名
  450. NSString *uniquePath=[[paths objectAtIndex:0] stringByAppendingPathComponent:fileName];
  451. BOOL blHave=[[NSFileManager defaultManager] fileExistsAtPath:uniquePath];
  452. if (!blHave) {
  453. NSLog(@"no have");
  454. return ;
  455. }else {
  456. NSLog(@" have");
  457. BOOL blDele= [fileManager removeItemAtPath:uniquePath error:nil];
  458. if (blDele) {
  459. NSLog(@"dele success");
  460. }else {
  461. NSLog(@"dele fail");
  462. }
  463. }
  464. }
  465. //遍历文件夹获得文件夹大小,返回多少M
  466. - (float )folderSizeAtPath:(NSString*) folderPath{
  467. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
  468. //文件名
  469. folderPath=[[paths objectAtIndex:0] stringByAppendingPathComponent:folderPath];
  470. NSFileManager* manager = [NSFileManager defaultManager];
  471. if (![manager fileExistsAtPath:folderPath]) return 0;
  472. NSEnumerator *childFilesEnumerator = [[manager subpathsAtPath:folderPath] objectEnumerator];
  473. NSString* fileName;
  474. long long folderSize = 0;
  475. while ((fileName = [childFilesEnumerator nextObject]) != nil){
  476. NSString* fileAbsolutePath = [folderPath stringByAppendingPathComponent:fileName];
  477. folderSize += [self fileSizeAtPath:fileAbsolutePath];
  478. }
  479. return folderSize/(1024.0*1024.0);
  480. }
  481. //单个文件的大小
  482. - (long long) fileSizeAtPath:(NSString*) filePath{
  483. NSFileManager* manager = [NSFileManager defaultManager];
  484. if ([manager fileExistsAtPath:filePath]){
  485. return [[manager attributesOfItemAtPath:filePath error:nil] fileSize];
  486. }
  487. return 0;
  488. }
  489. @end