// // PBSetViewController.m // IphoneBIMe // // Created by zjf on 2020/7/23. // Copyright © 2020 ProBIM. All rights reserved. // #import "PBSetViewController.h" #import "PBChangePWController.h" #import "PBLoginViewController.h" #import @interface PBSetViewController () @property (nonatomic, weak) UILabel *cacheSizeL; @end @implementation PBSetViewController - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.navigationController setNavigationBarHidden:NO animated:animated]; } - (void)viewDidLoad { [super viewDidLoad]; [self setupNav]; [self setupUI]; [self folderSize]; } - (void)setupNav { self.title = @"设置"; UIBarButtonItem *backNavItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"arrow_left"] style:UIBarButtonItemStylePlain target:self action:@selector(backItemAction)]; self.navigationItem.leftBarButtonItem = backNavItem; } - (void)backItemAction { [self.navigationController popViewControllerAnimated:YES]; } - (void)setupUI { self.title = @"设置"; self.view.backgroundColor = PBColor(244, 245, 246); CGFloat topH = 20.f; if (IS_IPHONE_X) { topH = 20.f + 24.f; } UIImageView *imageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"card_bg"]]; [self.view addSubview:imageV]; [imageV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view).offset(topH); make.left.equalTo(self.view).offset(20); make.right.equalTo(self.view).offset(-20); make.height.equalTo(@180); }]; UILabel *nameL = [UILabel z_labelWithText:Realname Color:[UIColor whiteColor] isBold:YES Font:22]; [self.view addSubview:nameL]; [nameL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(imageV).offset(20); make.left.equalTo(imageV).offset(20); make.height.equalTo(@30); make.right.equalTo(imageV).offset(-100); }]; // UILabel *companyL = [UILabel z_labelWithText:@"北京东晨工元科技发展有限公司" Color:[UIColor whiteColor] isBold:NO Font:14]; // [self.view addSubview:companyL]; // [companyL mas_makeConstraints:^(MASConstraintMaker *make) { // make.bottom.equalTo(imageV).offset(-20); // make.left.equalTo(imageV).offset(20); // make.right.equalTo(imageV).offset(-15); // make.height.equalTo(@20); // }]; UIView *bgV = [[UIView alloc] init]; bgV.backgroundColor = [UIColor whiteColor]; [self.view addSubview:bgV]; [bgV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(imageV.mas_bottom).offset(20); make.left.equalTo(self.view).offset(12); make.right.equalTo(self.view).offset(-12); make.height.equalTo(@50); }]; [bgV circleViewWithRadius:6]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(changepwAction:)]; bgV.userInteractionEnabled = YES; [bgV addGestureRecognizer:tap]; UILabel *changepwL = [UILabel z_labelWithText:@"密码" Color:PBColor(97, 111, 125) isBold:NO Font:15]; [self.view addSubview:changepwL]; [changepwL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(bgV).offset(15); make.centerY.equalTo(bgV); }]; UILabel *titleL = [UILabel z_labelWithText:@"修改密码" Color:PBColor(40, 58, 79) isBold:YES Font:16]; [self.view addSubview:titleL]; [titleL mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(bgV).offset(-36); make.centerY.equalTo(bgV); }]; UIImageView *rightImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"set_arrow_right"]]; [self.view addSubview:rightImageV]; [rightImageV mas_makeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(16, 16)); make.right.equalTo(bgV).offset(-10); make.centerY.equalTo(bgV); }]; UIView *bg1V = [[UIView alloc] init]; bg1V.backgroundColor = [UIColor whiteColor]; [self.view addSubview:bg1V]; [bg1V mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(bgV.mas_bottom).offset(8); make.left.equalTo(self.view).offset(12); make.right.equalTo(self.view).offset(-12); make.height.equalTo(@50); }]; [bg1V circleViewWithRadius:6]; UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cacheAction:)]; bg1V.userInteractionEnabled = YES; [bg1V addGestureRecognizer:tap1]; UILabel *cacheL = [UILabel z_labelWithText:@"清空缓存" Color:PBColor(97, 111, 125) isBold:NO Font:15]; [self.view addSubview:cacheL]; [cacheL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(bg1V).offset(15); make.centerY.equalTo(bg1V); }]; UILabel *cacheSizeL = [UILabel z_labelWithText:@"34M" Color:PBColor(40, 58, 79) isBold:YES Font:16]; [self.view addSubview:cacheSizeL]; [cacheSizeL mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(bg1V).offset(-15); make.centerY.equalTo(bg1V); }]; UIButton *quitBtn = [UIButton z_bgImageButton:[UIImage imageNamed:@"quit"]]; [quitBtn addTarget:self action:@selector(quitAction:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:quitBtn]; CGFloat bottom = 10; if (IS_IPHONE_X) { bottom = 10 + IPHONE_X_BOTTOM; } [quitBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self.view).offset(-bottom); make.left.equalTo(self.view).offset(10); make.right.equalTo(self.view).offset(-10); make.height.equalTo(@46); }]; self.cacheSizeL = cacheSizeL; } - (void)folderSize{ CGFloat folderSize = 0.0; NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES)firstObject]; NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachePath]; NSLog(@"文件数:%ld",files.count); for(NSString *path in files) { NSString*filePath = [cachePath stringByAppendingString:[NSString stringWithFormat:@"/%@",path]]; //累加 folderSize += [[NSFileManager defaultManager]attributesOfItemAtPath:filePath error:nil].fileSize; } //转换为M为单位 CGFloat sizeM = folderSize /1024.0/1024.0; self.cacheSizeL.text = [NSString stringWithFormat:@"%.2fM", sizeM]; } - (void)changepwAction:(UITapGestureRecognizer *)tap { PBChangePWController *changePwVC = [[PBChangePWController alloc] init]; changePwVC.ChangePWCompleteBlock = ^{ [self.navigationController popViewControllerAnimated:NO]; if (self.ToLoginBlock) { self.ToLoginBlock(); } }; [self.navigationController pushViewController:changePwVC animated:YES]; } - (void)cacheAction:(UITapGestureRecognizer *)tap { [self clearCache]; } - (void)quitAction:(UIButton *)btn { [YJProgressHUD showProgress:@"正在退出" inView:self.view]; NSFileManager *manager=[NSFileManager defaultManager]; NSString *filepath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0]stringByAppendingPathComponent:@"login.plist"];//这里就是你将要删除的沙盒路径(.plist文件,名字 [manager removeItemAtPath:filepath error:nil]; [JPUSHService deleteAlias:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) { NSLog(@"%zd--%@--%zd",iResCode,iAlias,seq); } seq:10]; [[PBNetworkTools sharedTools] RemoveTokenAndCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) { if (error) { NSLog(@"%@",error); [YJProgressHUD showMessage:@"退出登录失败" inView:self.view]; return; } NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str]; if (networkModel.Ret == 1) { [YJProgressHUD hide]; [self.navigationController popViewControllerAnimated:NO]; if (self.ToLoginBlock) { self.ToLoginBlock(); } }else { [YJProgressHUD showMessage:networkModel.Msg inView:self.view]; } }]; } - (void)clearCache { UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"将删除所有缓存数据" message:@"" preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertAction *clearAction = [UIAlertAction actionWithTitle:@"清除缓存" style:(UIAlertActionStyleDestructive) handler:^(UIAlertAction * _Nonnull action) { [YJProgressHUD showProgress:@"正在删除" inView:self.view]; NSFileManager *fileManager = [NSFileManager defaultManager]; NSString * cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]; NSLog(@"%@",cachePath); NSDirectoryEnumerator *fileEnumerator = [fileManager enumeratorAtPath:cachePath]; for (NSString *fileName in fileEnumerator) { NSString *filePath = [cachePath stringByAppendingPathComponent:fileName]; [fileManager removeItemAtPath:filePath error:nil]; } [YJProgressHUD showMessage:@"删除完成" inView:self.view]; self.cacheSizeL.text = @"0M"; }]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil]; [alertVC addAction:clearAction]; [alertVC addAction:cancelAction]; [self presentViewController:alertVC animated:YES completion:nil]; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end