| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- //
- // MOVerifyCodeVC.m
- // MiMoLive
- //
- // Created by MiMo on 2025/6/3.
- //
- #import "MOVerifyCodeVC.h"
- #import "UIImage+YYAdd.h"
- #import "MOInputCodeView.h"
- #import "MOLoginManager.h"
- #define kMOVerifycodeTime 120
- @interface MOVerifyCodeVC ()
- @property (nonatomic, strong) UIImageView *bgImgView;
- @property (nonatomic, strong) BigBtn *backButton;
- @property (nonatomic, strong) UILabel *titleLabel;
- @property (nonatomic, strong) UILabel *sendLabel;
- @property (nonatomic, strong) UILabel *phoneLabel;
- @property (nonatomic, strong) MOInputCodeView *codeView;
- @property (nonatomic, strong) UILabel *countdownLabel;
- @property (nonatomic, strong) UIButton *resendButton;
- @property (nonatomic, copy) NSString *countryCode;
- @property (nonatomic, copy) NSString *phone;
- @property (nonatomic, strong) NSTimer *countdownTimer;
- @property (nonatomic, assign) NSInteger countdownSeconds;
- /** 是否越狱 */
- @property (nonatomic, assign) BOOL isRootMobile;
- /** 是否虚拟设备 */
- @property (nonatomic, assign) BOOL isVirtual;
- @end
- @implementation MOVerifyCodeVC
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
-
- [self.navigationController setNavigationBarHidden:YES animated:animated];
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
-
- [self stopTimer];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self setupUI];
- self.isRootMobile = [SecurityBridge isJailbroken];//是否越狱
- self.isVirtual = [SecurityBridge isRunningInEmulator];//是否虚拟机
- [self startTimer];
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self.codeView showKeyboard];
- });
- }
- - (void)setupUI {
- [self.view addSubview:self.bgImgView];
- [self.bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_equalTo(0);
- }];
-
- [self.view addSubview:self.backButton];
- [self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(kTopSafeAreaInset + 10);
- make.left.mas_equalTo(12);
- make.size.mas_equalTo(CGSizeMake(30, 30));
- }];
-
- [self.view addSubview:self.titleLabel];
- [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.backButton.mas_bottom).offset(30);
- make.left.mas_equalTo(24);
- make.right.mas_equalTo(-36);
- }];
-
- [self.view addSubview:self.sendLabel];
- [self.sendLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.titleLabel.mas_bottom).offset(16);
- make.left.mas_equalTo(24);
- make.right.mas_equalTo(-24);
- }];
-
- [self.view addSubview:self.phoneLabel];
- [self.phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.sendLabel.mas_bottom).offset(2);
- make.left.mas_equalTo(24);
- make.right.mas_equalTo(-24);
- }];
-
- [self.view addSubview:self.codeView];
- [self.codeView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.phoneLabel.mas_bottom).offset(24);
- make.left.mas_equalTo(24);
- make.right.mas_equalTo(-24);
- make.height.mas_equalTo(kScaleWidth(64));
- }];
-
- [self.view addSubview:self.countdownLabel];
- [self.countdownLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.codeView.mas_bottom).offset(40);
- make.left.mas_equalTo(20);
- make.right.mas_equalTo(-24);
- }];
-
- [self.view addSubview:self.resendButton];
- [self.resendButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.countdownLabel);
- make.left.mas_equalTo(20);
- }];
- }
- - (void)startTimer {
-
- if (self.countryCode.length == 0 || self.phone.length == 0) {
- return;
- }
-
- self.countdownSeconds = kMOVerifycodeTime;
- self.resendButton.hidden = YES;
- self.countdownLabel.hidden = NO;
- self.countdownLabel.text = [NSString stringWithFormat:@"%@ %zds", NSLocalString(@"mimo_login_resend_code_countdown"), self.countdownSeconds];
- self.countdownTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateCountdown) userInfo:nil repeats:YES];
- }
- - (void)updateCountdown {
- self.countdownSeconds--;
- if (self.countdownSeconds <= 0) {
- [self stopTimer];
- self.countdownLabel.hidden = YES;
- self.resendButton.hidden = NO;
- } else {
- self.countdownLabel.text = [NSString stringWithFormat:@"%@ %zds", NSLocalString(@"mimo_login_resend_code_countdown"), self.countdownSeconds];
- }
- }
- - (void)stopTimer {
- [self.countdownTimer invalidate];
- self.countdownTimer = nil;
- }
- - (void)resendButtonAction {
- WEAKSELF
- [self sendSmsClickAndBlock:^(BOOL isSuccess) {
- if (isSuccess) {
- [weakSelf startTimer];
- }
- }];
- }
- -(void)sendSmsClickAndBlock:(void (^)(BOOL isSuccess))block{
-
- [MBProgressHUD showActivityMessageInView:@""];
- WEAKSELF
- NSDictionary *dic = @{@"code":self.countryCode,
- @"num":self.phone};
- [kHttpManager loginAndGetMobileCodeWithParams:dic andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
-
- [MBProgressHUD hideHUD];
-
- if(kCode_Success){
- [MBProgressHUD showTipMessageInView:NSLocalString(@"mimo_login_hint_verify_code")];
- block ? block(YES) : nil;
- }
- else{
- kShowNetError(data)
- block ? block(NO) : nil;
- }
- }];
- }
- - (void)setupCountryCode:(NSString *)countryCode phone:(NSString *)phone {
- self.phoneLabel.text = [NSString stringWithFormat:@"%@ %@", countryCode, phone];
- _countryCode = countryCode;
- _phone = phone;
- }
- - (void)backButtonAction {
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (UIImageView *)bgImgView {
- if (!_bgImgView) {
- _bgImgView = [[UIImageView alloc] init];
- _bgImgView.image = [UIImage imageNamed:@"img_login_bg"];
- }
- return _bgImgView;
- }
- - (BigBtn *)backButton {
- if (!_backButton) {
- _backButton = [[BigBtn alloc] init];
- [_backButton setImage:[UIImage imageNamed:@"icon_login_back_white"] forState:UIControlStateNormal];
- [_backButton addTarget:self action:@selector(backButtonAction) forControlEvents:UIControlEventTouchUpInside];
- }
- return _backButton;
- }
- - (UILabel *)titleLabel {
- if (!_titleLabel) {
- _titleLabel = [[UILabel alloc] init];
- _titleLabel.text = NSLocalString(@"mimo_login_input_code");
- _titleLabel.font = [MOTextTools poppinsBoldFont:24];
- _titleLabel.textColor = [MOTools colorWithHexString:@"#FFFFFF"];
- _titleLabel.numberOfLines = 0;
- }
- return _titleLabel;
- }
- - (UILabel *)sendLabel {
- if (!_sendLabel) {
- _sendLabel = [[UILabel alloc] init];
- _sendLabel.text = NSLocalString(@"mimo_login_send_code");
- _sendLabel.textColor = [MOTools colorWithHexString:@"#FFFFFF" alpha:0.5];
- _sendLabel.font = [MOTextTools regularFont:14];
- }
- return _sendLabel;
- }
- - (UILabel *)phoneLabel {
- if (!_phoneLabel) {
- _phoneLabel = [[UILabel alloc] init];
- _phoneLabel.textColor = [MOTools colorWithHexString:@"#FFFFFF" alpha:0.5];
- _phoneLabel.font = [MOTextTools regularFont:14];
- }
- return _phoneLabel;
- }
- - (MOInputCodeView *)codeView {
- if (!_codeView) {
- _codeView = [[MOInputCodeView alloc] init];
- WEAKSELF
- _codeView.inputCompleted = ^(NSString *code) {
- [MBProgressHUD showActivityMessageInView:@""];
- NSDictionary *mobileDict = @{@"code": weakSelf.countryCode,
- @"num": weakSelf.phone};
-
- NSDictionary *dict = @{@"mobile": mobileDict,
- @"code": code,
- @"root": @(weakSelf.isRootMobile),
- @"virtual": @(weakSelf.isVirtual)};
-
- [[MOLoginManager shareManager] loginByMobileCodeWithDict:dict];
- };
- }
- return _codeView;
- }
- - (UILabel *)countdownLabel {
- if (!_countdownLabel) {
- _countdownLabel = [[UILabel alloc] init];
- _countdownLabel.textColor = [MOTools colorWithHexString:@"#999999"];
- _countdownLabel.font = [MOTextTools regularFont:14];
- _countdownLabel.text = NSLocalString(@"mimo_login_resend_code_countdown");
- _countdownLabel.numberOfLines = 0;
- }
- return _countdownLabel;
- }
- - (UIButton *)resendButton {
- if (!_resendButton) {
- _resendButton = [[UIButton alloc] init];
- _resendButton.titleLabel.font = [MOTextTools regularFont:14];
- [_resendButton setTitleColor:[MOTools colorWithHexString:@"#999999"] forState:UIControlStateNormal];
- [_resendButton setTitle:NSLocalString(@"mimo_login_resend_code") forState:UIControlStateNormal];
- [_resendButton addTarget:self action:@selector(resendButtonAction) forControlEvents:UIControlEventTouchUpInside];
- _resendButton.hidden = YES;
- }
- return _resendButton;
- }
- @end
|