123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- //
- // SetPWDSecondViewController.m
- // 隐私保护
- //
- // Created by APPLE on 2023/9/19.
- //
- #import "SetPWDSecondViewController.h"
- #import <Masonry.h>
- #import "connectDeviceManager.h"
- #import "privacyModeTipViewController.h"
- @interface SetPWDSecondViewController (){
- NSString *pwd;
- UILabel *pointView0;
- UILabel *pointView1;
- UILabel *pointView2;
- UILabel *pointView3;
-
- UILabel *topLabel;
- UIButton *keyBoardBtn0;
- }
- @end
- @implementation SetPWDSecondViewController
- @synthesize oldPWD;
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- pwd = @"";
- [self drawAnyView];
- }
- - (void)drawAnyView{
- [self.navigationBar setHidden:YES];
- [self.toolBar setHidden:YES];
-
- [self.view setBackgroundColor:HWF5F7FAColor];
-
- /*上一步按钮*/
- UIButton *upStepBtn = [[UIButton alloc] init];
- [upStepBtn setTitle:NSLocalizedString(@"guide_set_pwd_up_step",nil) forState:(UIControlStateNormal)];
- [upStepBtn setTitleColor:HW05BAFBColor forState:(UIControlStateNormal)];
- [upStepBtn.titleLabel setFont:[UIFont systemFontOfSize:16]];
- [upStepBtn addTarget:self.navigationController
- action:@selector(popViewControllerAnimated:)
- forControlEvents:(UIControlEventTouchUpInside)];
- upStepBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- [self.view addSubview:upStepBtn];
- [upStepBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(10.f);
- make.width.mas_equalTo(100.f);
- make.top.mas_equalTo(5.f + H_STATE_BAR);
- make.height.mas_equalTo(32.f);
- }];
-
- /*设置密码标题*/
- topLabel = [[UILabel alloc] init];
- [topLabel setFont:[UIFont boldSystemFontOfSize:16.f]];
- [topLabel setTextColor:HW333333Color];
- [topLabel setTextAlignment:(NSTextAlignmentCenter)];
- [topLabel setText:NSLocalizedString(@"guide_set_pwd_makesure_title",nil)];
- [self.view addSubview:topLabel];
- [topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(20);
- make.right.mas_equalTo(-20);
- make.top.mas_equalTo(99.f + H_STATE_BAR);
- }];
-
- CGFloat w_pwd = 24.f;
- CGFloat h_pwd = 24.f;
-
- CGFloat pointFont = 20.f;
- /*密码视图*/
- pointView0 = [[UILabel alloc] init];
- [pointView0 setTextColor:HW0A132BColor];
- [pointView0 setBackgroundColor:HWE3E8F1Color];
- [pointView0 setClipsToBounds:YES];
- [pointView0 setTextAlignment:(NSTextAlignmentCenter)];
- [pointView0 setFont:[UIFont systemFontOfSize:pointFont]];
- [pointView0.layer setCornerRadius:w_pwd/2.f];
- [self.view addSubview:pointView0];
- [pointView0 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.view.mas_centerX).offset((0-2)*(w_pwd+w_pwd) + w_pwd/2.f);
- make.height.mas_equalTo(h_pwd);
- make.width.mas_equalTo(w_pwd);
- make.top.mas_equalTo(151.f + H_STATE_BAR);
- }];
-
- pointView1 = [[UILabel alloc] init];
- [pointView1 setTextColor:HW0A132BColor];
- [pointView1 setBackgroundColor:HWE3E8F1Color];
- [pointView1 setClipsToBounds:YES];
- [pointView1 setTextAlignment:(NSTextAlignmentCenter)];
- [pointView1 setFont:[UIFont systemFontOfSize:pointFont]];
- [pointView1.layer setCornerRadius:w_pwd/2.f];
- [self.view addSubview:pointView1];
- [pointView1 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.view.mas_centerX).offset((1-2)*(w_pwd+w_pwd) + w_pwd/2.f);
- make.height.mas_equalTo(h_pwd);
- make.width.mas_equalTo(w_pwd);
- make.top.mas_equalTo(151.f + H_STATE_BAR);
- }];
-
- pointView2 = [[UILabel alloc] init];
- [pointView2 setTextColor:HW0A132BColor];
- [pointView2 setBackgroundColor:HWE3E8F1Color];
- [pointView2 setClipsToBounds:YES];
- [pointView2 setTextAlignment:(NSTextAlignmentCenter)];
- [pointView2 setFont:[UIFont systemFontOfSize:pointFont]];
- [pointView2.layer setCornerRadius:w_pwd/2.f];
- [self.view addSubview:pointView2];
- [pointView2 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.view.mas_centerX).offset((2-2)*(w_pwd+w_pwd) + w_pwd/2.f);
- make.height.mas_equalTo(h_pwd);
- make.width.mas_equalTo(w_pwd);
- make.top.mas_equalTo(151.f + H_STATE_BAR);
- }];
-
- pointView3 = [[UILabel alloc] init];
- [pointView3 setTextColor:HW0A132BColor];
- [pointView3 setBackgroundColor:HWE3E8F1Color];
- [pointView3 setClipsToBounds:YES];
- [pointView3 setTextAlignment:(NSTextAlignmentCenter)];
- [pointView3 setFont:[UIFont systemFontOfSize:pointFont]];
- [pointView3.layer setCornerRadius:w_pwd/2.f];
- [self.view addSubview:pointView3];
- [pointView3 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.view.mas_centerX).offset((3-2)*(w_pwd+w_pwd) + w_pwd/2.f);
- make.height.mas_equalTo(h_pwd);
- make.width.mas_equalTo(w_pwd);
- make.top.mas_equalTo(151.f + H_STATE_BAR);
- }];
-
- /*下方绘制键盘按钮*/
- UIView *bgViewForNumberBoard = [[UIView alloc] init];
- [bgViewForNumberBoard setBackgroundColor:[UIColor clearColor]];
- CGFloat w_bgViewForNumberBoard = SCREEN_W - 2*22.f*AUTOSCALE;
- CGFloat h_bgViewForNumberBoard = 330.f;
- [self.view addSubview:bgViewForNumberBoard];
- [bgViewForNumberBoard mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(22.f*AUTOSCALE);
- make.height.mas_equalTo(h_bgViewForNumberBoard);
- make.width.mas_equalTo(w_bgViewForNumberBoard);
- make.bottom.mas_equalTo(-70.f);
- }];
-
- CGFloat w_key_btn = w_bgViewForNumberBoard/3.f;
- CGFloat h_key_btn = h_bgViewForNumberBoard/4.f;
-
- /*绘制键盘 1~9*/
- for (NSInteger nFori = 0; nFori < 9; nFori++) {
- CGFloat x_key_btn = (nFori%3)*w_key_btn;
- CGFloat y_key_btn = (nFori/3)*h_key_btn;
-
- UIButton *keyBoardBtn = [[UIButton alloc] init];
- [keyBoardBtn setBackgroundColor:[UIColor clearColor]];
- [keyBoardBtn setTitleColor:HW0A132BColor forState:(UIControlStateNormal)];
- [keyBoardBtn.titleLabel setFont:[UIFont boldSystemFontOfSize:40.f]];
- [keyBoardBtn setTitle:[NSString stringWithFormat:@"%ld",nFori+1] forState:(UIControlStateNormal)];
- [keyBoardBtn addTarget:self action:@selector(keyBoardBtnPressed:) forControlEvents:(UIControlEventTouchUpInside)];
- [bgViewForNumberBoard addSubview:keyBoardBtn];
- [keyBoardBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(x_key_btn);
- make.top.mas_equalTo(y_key_btn);
- make.width.mas_equalTo(w_key_btn);
- make.height.mas_equalTo(h_key_btn);
- }];
- }
-
- /*删除按钮*/
- UIButton *deleteBoardBtn = [[UIButton alloc] init];
- [deleteBoardBtn setBackgroundColor:[UIColor clearColor]];
- [deleteBoardBtn addTarget:self action:@selector(deleteBoardBtnPressed) forControlEvents:(UIControlEventTouchUpInside)];
- [deleteBoardBtn setImage:[UIImage imageNamed:@"key_board_delete"] forState:(UIControlStateNormal)];
- [bgViewForNumberBoard addSubview:deleteBoardBtn];
- [deleteBoardBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(0);
- make.bottom.mas_equalTo(0);
- make.width.mas_equalTo(w_key_btn);
- make.height.mas_equalTo(h_key_btn);
- }];
-
- /*0*/
- keyBoardBtn0 = [[UIButton alloc] init];
- [keyBoardBtn0 setBackgroundColor:[UIColor clearColor]];
- [keyBoardBtn0 setTitleColor:HW0A132BColor forState:(UIControlStateNormal)];
- [keyBoardBtn0 setTitleColor:COLOR_PACEHOLDER forState:(UIControlStateDisabled)];
- [keyBoardBtn0.titleLabel setFont:[UIFont boldSystemFontOfSize:40.f]];
- [keyBoardBtn0 setTitle:@"0" forState:(UIControlStateNormal)];
- [keyBoardBtn0 addTarget:self action:@selector(keyBoardBtnPressed:) forControlEvents:(UIControlEventTouchUpInside)];
- keyBoardBtn0.enabled = NO;
- [bgViewForNumberBoard addSubview:keyBoardBtn0];
- [keyBoardBtn0 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(w_key_btn);
- make.bottom.mas_equalTo(0);
- make.width.mas_equalTo(w_key_btn);
- make.height.mas_equalTo(h_key_btn);
- }];
-
- /*OK*/
- UIButton *keyBoardBtnOK = [[UIButton alloc] init];
- [keyBoardBtnOK setBackgroundColor:[UIColor clearColor]];
- [keyBoardBtnOK setTitleColor:HW13B2EBColor forState:(UIControlStateNormal)];
- [keyBoardBtnOK.titleLabel setFont:[UIFont boldSystemFontOfSize:30.f]];
- [keyBoardBtnOK setTitle:@"OK" forState:(UIControlStateNormal)];
- [keyBoardBtnOK addTarget:self action:@selector(keyBoardBtnOKPressed) forControlEvents:(UIControlEventTouchUpInside)];
- [bgViewForNumberBoard addSubview:keyBoardBtnOK];
- [keyBoardBtnOK mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(2*w_key_btn);
- make.bottom.mas_equalTo(0);
- make.width.mas_equalTo(w_key_btn);
- make.height.mas_equalTo(h_key_btn);
- }];
- }
- - (void)deleteBoardBtnPressed{
- if (pwd.length > 0){
- NSInteger numberLength = pwd.length;
- if (numberLength == 1){
- [pointView0 setText:@""];
- [pointView0 setBackgroundColor:HWE3E8F1Color];
- self->keyBoardBtn0.enabled = NO;
- }else if (numberLength == 2){
- [pointView1 setText:@""];
- [pointView1 setBackgroundColor:HWE3E8F1Color];
- }else if (numberLength == 3){
- [pointView2 setText:@""];
- [pointView2 setBackgroundColor:HWE3E8F1Color];
- }else if (numberLength == 4){
- [pointView3 setText:@""];
- [pointView3 setBackgroundColor:HWE3E8F1Color];
- }
-
- pwd = [pwd substringToIndex:numberLength-1];
- }
- }
- - (void)keyBoardBtnOKPressed{
- if (pwd.length == 4){
- if ([pwd isEqualToString:oldPWD]) {
- /*设置密码成功*/
- NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
- NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithDictionary:deviceDict];
- [dict setObject:pwd forKey:Const_Have_Add_Device_PWD];
- [HWDataManager setObjectWithKey:Const_Have_Add_Device value:dict];
-
-
- if (deviceDict && [[deviceDict allKeys] containsObject:Const_Have_Add_Device_SN]){
- //有设备了先去做链接准备 // 80bec9c5
- NSString *SNStr = deviceDict[@"Const_Have_Add_Device_SN"];
- if(SNStr){
- KWeakSelf
- [[netWorkManager shareInstance] updateCardInfoBySN:SNStr withPwdStr:pwd didNetEnd:^(NSInteger didSuc) {
-
- if(didSuc){
- [weakSelf getPwdFunBy:SNStr];
- }
- else{
- [[iToast makeText:NSLocalizedString(@"log_login_system_busy",nil)] show];
- }
- }];
- }
- }
-
-
- }else{
- /*提示密码不一致*/
- [topLabel setText:NSLocalizedString(@"guide_set_pwd_no_same",nil)];
- }
- }
- }
- - (void)keyBoardBtnPressed:(id)sender{
- UIButton *btn = (UIButton *)sender;
- NSString *selectNumberStr = btn.titleLabel.text;
- if (pwd.length < 4){
- NSInteger numberLength = pwd.length;
- if (numberLength == 0){
- [pointView0 setText:selectNumberStr];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self->pointView0 setBackgroundColor:HW0A132BColor];
- self->keyBoardBtn0.enabled = YES;
- });
- }else if (numberLength == 1){
- [pointView1 setText:selectNumberStr];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self->pointView1 setBackgroundColor:HW0A132BColor];
- });
- }else if (numberLength == 2){
- [pointView2 setText:selectNumberStr];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self->pointView2 setBackgroundColor:HW0A132BColor];
- });
- }else if (numberLength == 3){
- [pointView3 setText:selectNumberStr];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self->pointView3 setBackgroundColor:HW0A132BColor];
- });
- }
-
- pwd = [pwd stringByAppendingString:selectNumberStr];
- }
- }
- #pragma mark 重新获取密码
- -(void)getPwdFunBy:(NSString*)SNStr
- {
- KWeakSelf
- // [[connectDeviceManager shareInstance] getThridMsgBySN:SNStr needReconnect:NO didNetEnd:^(NSInteger didSuc) {
- //
- // if(didSuc){
- // if(self->_isForgetPwdType){
- // [[NSNotificationCenter defaultCenter] postNotificationName:forgetPwdDidSetNotification object:nil];
- // }
- // else{
- //// [[NSNotificationCenter defaultCenter] postNotificationName:GuideOkNotification object:nil];
- // [weakSelf gotoPrivacyModeTipVCFun];
- // }
- //
- // }
- // else{
- // [[iToast makeText:NSLocalizedString(@"log_login_system_busy",nil)] show];
- // }
- //
- // }];
-
- [[netWorkManager shareInstance] getThridMsgBySN:SNStr success:^(id _Nonnull responseObject) {
- DeviceThirdIdModel *model = responseObject;
- if([model isKindOfClass:[DeviceThirdIdModel class]]){
-
- if(model.status == 0 && model.data){
- if(self->_isForgetPwdType){
- [[NSNotificationCenter defaultCenter] postNotificationName:forgetPwdDidSetNotification object:nil];
- }
- else{
- // [[NSNotificationCenter defaultCenter] postNotificationName:GuideOkNotification object:nil];
- [weakSelf gotoPrivacyModeTipVCFun];
- }
- }
- else{
- [[iToast makeText:NSLocalizedString(@"log_login_system_busy",nil)] show];
- }
- }
- else{
- [[iToast makeText:NSLocalizedString(@"log_login_system_busy",nil)] show];
- }
-
- } failure:^(NSError * _Nonnull error) {
- [[iToast makeText:NSLocalizedString(@"log_login_system_busy",nil)] show];
- }];
- }
- - (void)gotoPrivacyModeTipVCFun
- {
- privacyModeTipViewController *nextVC = [privacyModeTipViewController new];
- //[self.navigationController pushViewController:nextVC animated:YES];
-
- UIWindow* window = [iTools getKeyWindow];
- window.rootViewController = nextVC;
-
- //第一次没有主动链接的问题
- [[webRtcManager shareManager] beginToLinkWebRtcFun];
- }
- @end
|