// // LoginViewController.m // KulexiuForTeacher // // Created by Kyle on 2022/3/17. // #import "LoginViewController.h" #import "LoginBodyView.h" #import "VefiCodeLoginController.h" #import "PasswordLoginController.h" #import "KSBaseWKWebViewController.h" #import "UserInfoManager.h" #import "AppDelegate+AppService.h" @interface LoginViewController () @property (nonatomic, strong) LoginBodyView *bodyView; @end @implementation LoginViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.ks_prefersNavigationBarHidden = YES; [self configUI]; } - (void)configUI { _bodyView = [LoginBodyView shareInstance]; if (![NSString isEmptyString:UserDefault(PHONEKEY)]) { _bodyView.phoneField.text = UserDefault(PHONEKEY); } CGFloat height = KPortraitHeight; [self.scrollView addSubview:_bodyView]; [_bodyView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.scrollView.mas_top); make.right.left.mas_equalTo(self.view); make.height.mas_equalTo(height); }]; MJWeakSelf; [_bodyView loginActionCallback:^(LOGINACTION action, NSString * _Nonnull phoneNo) { [weakSelf operationWithType:action phone:phoneNo]; }]; } - (void)operationWithType:(LOGINACTION)action phone:(NSString *)phone { switch (action) { case LOGINACTION_CODE: { if (![NSString isMobilePhoneNumber:phone]) { [LOADING_MANAGER MBShowAUTOHidingInWindow:@"手机号码输入有误"]; return; } VefiCodeLoginController *ctrl = [[VefiCodeLoginController alloc] init]; ctrl.phoneNo = phone; [self.navigationController pushViewController:ctrl animated:YES]; } break; case LOGINACTION_PASSWORD: { PasswordLoginController *ctrl = [[PasswordLoginController alloc] init]; if (![NSString isEmptyString:phone]) { ctrl.phoneNo = phone; } [self.navigationController pushViewController:ctrl animated:YES]; } break; case LOGINACTION_REGPROTOCAL: // 注册协议 { KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init]; webCtrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST, @"/#/registerProtocol"]; [self.navigationController pushViewController:webCtrl animated:YES]; } break; case LOGINACTION_PRIVACY: // 隐私协议 { KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init]; webCtrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST, @"/#/privacyProtocol"]; [self.navigationController pushViewController:webCtrl animated:YES]; } break; case LOGINACTION_VERSIONCHECK: { [self versionCheck]; } break; default: break; } } - (void)versionCheck { NSString *currentVersion = [USER_MANAGER getCurrentVersion]; NSString *storeUrl = @"https://apps.apple.com/cn/app/%E9%85%B7%E4%B9%90%E7%A7%80%E5%AD%A6%E9%99%A2/id1626971149?uo=4"; [KSNetworkingManager appVersionInfoRequest:KS_GET success:^(NSDictionary * _Nonnull dic) { if ([dic ks_integerValueForKey:@"code"] == 200) { NSString *serviceVersion = [[dic ks_dictionaryValueForKey:@"data"] ks_stringValueForKey:@"version"]; if ([currentVersion isEqualToString:serviceVersion]) { [LOADING_MANAGER MBShowAUTOHidingInWindow:@"当前是最新版本"]; } else if ([USER_MANAGER isLowerVersionCompareLocalVersion:currentVersion serviceVersion:serviceVersion]) { // desc NSString *descMessage = [[dic ks_dictionaryValueForKey:@"data"] ks_stringValueForKey:@"description"]; if ([NSString isEmptyString:descMessage]) { descMessage = @""; } // 判断 NSMutableDictionary *parm = [NSMutableDictionary dictionary]; [parm setValue:serviceVersion forKey:@"memo"]; [parm setValue:descMessage forKey:@"descMessage"]; [parm setValue:storeUrl forKey:@"openUrl"]; if ([[dic ks_dictionaryValueForKey:@"data"] ks_boolValueForKey:@"isForceUpdate"]) { [parm setValue:@(YES) forKey:@"isforce"]; } else { [parm setValue:@(NO) forKey:@"isforce"]; } [AppDelegate shareAppDelegate].messageDict = parm; [[AppDelegate shareAppDelegate] showMemoAlert]; } else { [LOADING_MANAGER MBShowAUTOHidingInWindow:@"当前是最新版本"]; } } } faliure:^(NSError * _Nonnull error) { [LOADING_MANAGER MBShowAUTOHidingInWindow:@"当前是最新版本"]; }]; } /* #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