| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- //
- // RDSLoginVerifyCodeVC.m
- // SmartLightForBigFish
- //
- // Created by coderYK on 2017/11/17.
- // Copyright © 2017年 RD. All rights reserved.
- //
- #import "RDSLoginVerifyCodeVC.h"
- //#import "WLCaptcheButton.h"
- #import "RDSUserProtocolViewController.h"
- #import "NSString+verify.h"
- #import "UIView+RDSClip.h"
- #import "UIImage+Extension.h"
- #import "RDSRootControl.h"
- #import "RDSLoginPwdCodeVC.h"
- #import "RDCheckAppVersion.h"
- #import "YXAlertView.h"
- #import "RDSControlWebVC.h"
- @interface RDSLoginVerifyCodeVC ()<UITextFieldDelegate>
- @property (weak, nonatomic) IBOutlet UIButton *backBtn;
- @property (weak, nonatomic) IBOutlet UIButton *loginBtn;
- @property (weak, nonatomic) IBOutlet UIView *phoneBgView;
- @property (weak, nonatomic) IBOutlet UIView *codeBgView;
- @property (weak, nonatomic) IBOutlet UITextField *phoneTF;
- @property (weak, nonatomic) IBOutlet UITextField *verifyCodeTF;
- @property (weak, nonatomic) IBOutlet UIButton *verifyCodeBtn;
- @property (weak, nonatomic) IBOutlet UIButton *agreeBtn;
- @property (weak, nonatomic) IBOutlet UIButton *userAgreement;
- @property (weak, nonatomic) IBOutlet UIButton *privacyPolicyBtn;
- @end
- @implementation RDSLoginVerifyCodeVC
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- // 隐藏导航栏
- self.fd_prefersNavigationBarHidden = YES;
-
- self.view.backgroundColor = [UIColor whiteColor];
- [self.backBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
-
- self.phoneBgView.layer.cornerRadius = 22.5;
- self.phoneBgView.layer.borderWidth = 1.0;
- self.phoneBgView.layer.borderColor = [UIColor whiteColor].CGColor;
-
- self.codeBgView.layer.cornerRadius = 22.5;
- self.codeBgView.layer.borderWidth = 1.0;
- self.codeBgView.layer.borderColor = [UIColor whiteColor].CGColor;
-
- NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@"请输入手机号" attributes: @{NSForegroundColorAttributeName:[UIColor whiteColor]}];
- self.phoneTF.attributedPlaceholder = attrString;
- self.phoneTF.text = TheDataManager.phone;
-
- NSAttributedString *attrString2 = [[NSAttributedString alloc] initWithString:@"请输入验证码" attributes: @{NSForegroundColorAttributeName:[UIColor whiteColor]}];
- self.verifyCodeTF.attributedPlaceholder = attrString2;
-
- [self p_setupTF];
-
- // 检查更新
- // [TheCheckAppVersion checkUpdate];
-
- // 这是rootControl 自动登录时会先进入这个页面,所有先隐藏
- if(!self.isPushVc){
- self.view.alpha = 0;
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- self.view.alpha = 1;
- });
- }
- }
- - (void)viewDidLayoutSubviews{
- [super viewDidLayoutSubviews];
-
- _verifyCodeBtn.layer.cornerRadius = _verifyCodeBtn.rds_height/2;
- }
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
-
- _agreeBtn.selected = NO;
-
- [self addAlertView];
- }
- -(void)addAlertView
- {
- NSString *state = [[NSUserDefaults standardUserDefaults] objectForKey:@"isShowAgreement"];
- if ([state intValue] == 0) {
- YXAlertView *alertView = [[YXAlertView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
- // UIWindow *window = [UIApplication sharedApplication].keyWindow;
- [self.view addSubview:alertView];
- alertView.cancleBtnClick = ^(YXAlertView * _Nonnull alertView) {
- [alertView removeFromSuperview];
- };
-
- alertView.sureBtnClick = ^(YXAlertView * _Nonnull alertView) {
- [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"isShowAgreement"];
- [alertView removeFromSuperview];
- };
-
- alertView.contentClick = ^(YXAlertView * _Nonnull view, NSString * _Nonnull urlStr) {
- RDSControlWebVC *webVc = [[RDSControlWebVC alloc]init];
- webVc.requestURL = urlStr;
- webVc.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:webVc animated:YES];
- };
- }
- }
- -(void)backAction:(UIButton *)btn
- {
- [self.navigationController popViewControllerAnimated:YES];
- }
- #pragma mark - Action
- - (IBAction)p_onPwdLogin {
-
- if(_isPushVc){
- [self popViewControllerAnimated:YES];
- }else{
- RDSLoginPwdCodeVC *vc = [[RDSLoginPwdCodeVC alloc] init];
- vc.isPushVc = YES;
- [self pushViewController:vc animated:YES];
- }
-
- }
- // 登录
- - (IBAction)p_onLogin {
-
- if (![self.phoneTF.text isPhoneNum]) {
- [RDSHudShower showBottomToast:@"请输入正确的手机号码"];
- return;
- }
- else if (self.verifyCodeTF.text.length < 1){
- [RDSHudShower showBottomToast:@"请输入验证码"];
- return;
- }
- else if (!self.agreeBtn.isSelected){
- [RDSHudShower showBottomToast:@"请先阅读并同意用户协议"];
- return;
- }
- [RDSHudShower showWithStatus:@"正在登录账户…" autoDismiss:NO];
- RDS_WEAKSELF(weakSelf)
- [RDSDemoApiHelper rds_loginWithVerifyCodePhone:self.phoneTF.text code:self.verifyCodeTF.text success:^(id responseObject) {
-
- if ([responseObject[@"code"] intValue] != 0) {
- [RDSHudShower showBottomToast:responseObject[@"message"]];
- }else{
- NSDictionary *data = responseObject[@"data"];
- NSString *access_token = data[@"access_token"];
- NSString *token_type = data[@"token_type"];
-
- if (access_token && token_type) {
- TheDataManager.token = [NSString stringWithFormat:@"%@ %@",token_type,access_token];
- }else{
- [RDSHudShower showBottomToast:@"系统错误"];
- return;
- }
-
- TheDataManager.isFirstLogin = [data[@"app_first_login"] boolValue];
-
- [weakSelf p_appInit];
-
- [RDSHudShower dismissHUD];
- [RDSRootControl shareControl].isLoginSuccess = YES;
- }
-
- } failure:^(NSError *error) {
- [RDSHudShower showBottomToast:@"连接服务器失败"];
- }];
- }
- -(void)p_appInit
- {
- [RDSDemoApiHelper rds_appInitWithType:@2 success:^(id responseObject) {
-
- } failure:^(NSError *error) {
-
- }];
- }
- - (IBAction)getVerifyCode:(UIButton *)verifyCodeBtn {
-
- if (![self.phoneTF.text isPhoneNum]) {
- [RDSHudShower showCenterToast:@"请输入正确的手机号码"];
- return;
- }
-
- //TheDataManager.phone = self.phoneTF.text;
- _verifyCodeTF.text = @"";
- [_verifyCodeTF becomeFirstResponder];
-
- [RDSHudShower showWithStatus:@"正在获取验证码…" autoDismiss:YES];
- RDS_WEAKSELF(weakSelf)
- [RDSDemoApiHelper rds_getVerifyCodePhone:self.phoneTF.text type:1 success:^(id responseObject) {
-
- [weakSelf timerButton:weakSelf.verifyCodeBtn];
-
- if ([responseObject[@"code"] intValue] != 0) {
- [RDSHudShower showBottomToast:responseObject[@"message"]];
- }
- else{
- [RDSHudShower showBottomToast:@"获取验证码成功"];
- }
-
- } failure:^(NSError *error) {
- [RDSHudShower showBottomToast:@"连接服务器失败"];
- DDLog(@"json data error:/n%@", error.description);
- }];
- [self.verifyCodeTF becomeFirstResponder];
- }
- #pragma - mark 倒计时
- -(void)timerButton:(UIButton *)button
- {
- __block int timeout = 60; //倒计时时间
- dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
- dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
- dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
- dispatch_source_set_event_handler(_timer, ^{
- if(timeout <= 0) //倒计时结束,关闭
- {
- dispatch_source_cancel(_timer);
- dispatch_async(dispatch_get_main_queue(), ^{
- //设置界面的按钮显示 根据自己需求设置
- button.userInteractionEnabled = YES;
- [button setTitle:@"获取验证码" forState:UIControlStateNormal];
- });
- } else {
- NSString *strTime = [NSString stringWithFormat:@"%ds重新获取",timeout];
- dispatch_async(dispatch_get_main_queue(), ^{
- //设置界面的按钮显示 根据自己需求设置
- [button setTitle:strTime forState:UIControlStateNormal];
- button.userInteractionEnabled = NO;
- });
- timeout--;
- }
- });
- dispatch_resume(_timer);
- }
- // 阅读并同意
- - (IBAction)p_onAgreeBtnClick:(UIButton *)sender {
-
- sender.selected = !sender.selected;
- }
- // 点击用户协议
- - (IBAction)p_onUserAgreementClick {
-
- // RDSUserProtocolViewController *userProtocolVC = [[RDSUserProtocolViewController alloc] init];
- // userProtocolVC.url = kUserAgreement;
- // userProtocolVC.vcTitle = @"用户协议";
- // [self pushViewController:userProtocolVC animated:YES];
-
- RDSControlWebVC *webVc = [[RDSControlWebVC alloc]init];
- webVc.requestURL = kUserAgreement;
- webVc.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:webVc animated:YES];
- }
- // 点击隐私政策
- - (IBAction)p_onPrivacyPolicyClick {
-
- // RDSUserProtocolViewController *userProtocolVC = [[RDSUserProtocolViewController alloc] init];
- // userProtocolVC.url = kPrivacyPolicy;
- // userProtocolVC.vcTitle = @"隐私政策";
- // [self pushViewController:userProtocolVC animated:YES];
-
- RDSControlWebVC *webVc = [[RDSControlWebVC alloc]init];
- webVc.requestURL = kPrivacyPolicy;
- webVc.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:webVc animated:YES];
- }
- #pragma mark - UITextFieldDelegate
- - (void)p_setupTF {
- self.phoneTF.delegate = self;
- self.verifyCodeTF.delegate = self;
- }
- - (BOOL)textFieldShouldReturn:(UITextField *)textField {
-
- if (textField == self.phoneTF) {
- [self.verifyCodeTF becomeFirstResponder];
- }
- else if (textField == self.verifyCodeTF) {
- [self.verifyCodeTF becomeFirstResponder];
- }
- else {
- [self p_onLogin];
- }
- return YES;
- }
- - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
- [self.view endEditing:YES];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (void)dealloc{
- DDLog(@"dealloc~~");
- }
- @end
|