当前位置:网站首页>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

边栏推荐
- Analyze the emotional elements contained in intelligent sweeping robot
- Can plastics comply with gb/t 2408 - Determination of flammability
- I've been in an outsourcing company for two years, and I feel like I'm going to die
- 猿辅导技术进化论:助力教与学 构想未来学校
- Transformer -- Analysis and application of attention model
- What should testers know about login security?
- 塑料可以执行GB/T 2408 -燃烧性能的测定吗
- Angr (XI) - official document (Part2)
- POJ 3417 network (lca+ differential on tree)
- 【ARXIV2204】Vision Transformers for Single Image Dehazing
猜你喜欢

What should testers know about login security?

Program life | how to switch to software testing? (software testing learning roadmap attached)

The first artificial intelligence security competition starts. Three competition questions are waiting for you to fight

After a year of unemployment, I learned to do cross-border e-commerce and earned 520000. Only then did I know that going to work really delayed making money!

Summary and review of puppeter

What SaaS architecture design do you need to know?

Easycvr Video Square snapshot adding device channel offline reason display

Service object creation and use

Check box error

MySQL(5)
随机推荐
Flink mind map
基于MPLS构建虚拟专网的配置实验
HDU 1914 the stable marriage problem
[internal mental skill] - creation and destruction of function stack frame (C implementation)
HDU 2874 connections between cities
What should testers know about login security?
Euler road / Euler circuit
Design and development of C language ATM system project
MySQL(5)
[daily question 1] 735. Planetary collision
HDU 1530 maximum clique
Method of converting UI file to py file
FreeRTOS startup process, coding style and debugging method
【内功心法】——函数栈帧的创建和销毁(C实现)
Look at the experience of n-year software testing summarized by people who came over the test
flink思维导图
Testcafe provides automatic waiting mechanism and live operation mode
Redis configuration file explanation / parameter explanation and elimination strategy
Dcgan:deep volume general adaptive networks -- paper analysis
UI automation test farewell from now on, manual download browser driver, recommended collection