当前位置:网站首页>Using RAC to realize the sending logic of verification code
Using RAC to realize the sending logic of verification code
2022-07-28 05:06:00 【Lu_ Ca】
Preface
In the project, mobile phone verification code login and registration pages have the need to send verification code . I have been using my own timer to do the corresponding processing before , I've been watching RAC Something related , I just see that the timer conforms to some previous design scenarios , It's a simple implementation .
Import RAC
My training program is Objective-C Project , So before podfile Add... To the document pod ‘ReactiveObjC’, ‘~> 3.0.0’, direct pod install
then , Import the header file on the required page #import "ReactiveObjC.h".
Specific code
#import "ViewController.h"
#import "ReactiveObjC.h"
@interface ViewController ()
@property (nonatomic, strong) RACDisposable *btnDispose;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
UIButton *button = [UIButton new];
[button setTitle:@" Send verification code " forState:UIControlStateNormal];
button.backgroundColor = [UIColor blueColor];
button.layer.cornerRadius = 0;
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
button.frame = CGRectMake(100, 100, 200, 40);
[self.view addSubview:button];
// Create the semaphore of the button click , And listen for click events
[[button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
button.enabled = NO;
__block int time = 5;
//subscribeNext Return to one RACDisposable, Can be used to unsubscribe
self.btnDispose = [[RACSignal interval:1.0 onScheduler:[RACScheduler mainThreadScheduler]] subscribeNext:^(NSDate * _Nullable x) {
// After the timer executes , utilize time To monitor whether the countdown is over
time--;
NSString *title = time == 0 ? @" Send verification code " : [NSString stringWithFormat:@" Please wait %d Second retransmission ",time];
[button setTitle:title forState:UIControlStateNormal];
button.enabled = time == 0 ? YES : NO;
button.layer.cornerRadius = 15;
button.backgroundColor = [UIColor greenColor];
if(time == 0){
button.layer.cornerRadius = 0;
button.backgroundColor = [UIColor blueColor];
// Unsubscribe
[self.btnDispose dispose];
}
}];
}];
}I changed the rounded corner and background color of the button after the countdown , It is convenient to distinguish different states . The renderings are as follows

边栏推荐
- Testcafe's positioning, operation of page elements, and verification of execution results
- Leetcode 18. sum of four numbers
- Testcafe provides automatic waiting mechanism and live operation mode
- Easycvr Video Square snapshot adding device channel offline reason display
- Pipe /createpipe
- FreeRTOS startup process, coding style and debugging method
- 【ARXIV2204】Vision Transformers for Single Image Dehazing
- 【CVPR2022 oral】Balanced Multimodal Learning via On-the-fly Gradient Modulation
- (clone virtual machine steps)
- 【ARXIV2205】Inception Transformer
猜你喜欢

Comprehensively analyze the differences between steam and maker Education

猿辅导技术进化论:助力教与学 构想未来学校

Analyze the emotional elements contained in intelligent sweeping robot

What is the reason why the easycvr national standard protocol access equipment is online but the channel is not online?

Win10 machine learning environment construction pycharm, anaconda, pytorch

MySQL(5)

Method of converting UI file to py file

The research group passed the thesis defense successfully
![[paper notes] - low illumination image enhancement - zeroshot - rrdnet Network - 2020-icme](/img/e3/f9c6bfdbcd5dffd406e3f1d2331050.png)
[paper notes] - low illumination image enhancement - zeroshot - rrdnet Network - 2020-icme

(clone virtual machine steps)
随机推荐
What should testers know about login security?
你必需要了解的saas架构设计?
Evolution of ape counseling technology: helping teaching and learning conceive future schools
MySQL 默认隔离级别是RR,为什么阿里等大厂会改成RC?
Introduction to testcafe
Test report don't step on the pit
Barbie q! How to analyze the new game app?
为什么md5不可逆,却还可能被md5免费解密网站解密
php7.1 连接sqlserver2008r2 如何测试成功
Melt cloud x chat, create a "stress free social" habitat with sound
MySQL(5)
Duoyu security browser will improve the security mode and make users browse more safely
Analyze the emotional elements contained in intelligent sweeping robot
【ARXIV2203】Efficient Long-Range Attention Network for Image Super-resolution
RT_ Use of thread mailbox
Testcafe provides automatic waiting mechanism and live operation mode
Euler road / Euler circuit
Professor dongjunyu made a report on the academic activities of "Tongxin sticks to the study of war and epidemic"
jsonp 单点登录 权限检验
Special topic of APP performance design and Optimization - poor implementation affecting performance