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

边栏推荐
- Melt cloud x chat, create a "stress free social" habitat with sound
- With a monthly salary of 15.5K, he failed to start a business and was heavily in debt. How did he reverse the trend through software testing?
- 【ARIXV2204】Neighborhood attention transformer
- C language classic 100 question exercise (1~21)
- Design and development of C language ATM system project
- What tools do software testers need to know?
- 阿里怎么用DDD来拆分微服务?
- App test process and test points
- 【CPU占用高】software_reporter_tool.exe
- list indices must be integers or slices, not tuple
猜你喜欢

Know etcd

RT based_ Distributed wireless temperature monitoring system of thread (I)

How to quickly locate bugs? How to write test cases?

Testcafe's positioning, operation of page elements, and verification of execution results

Activation functions sigmoid, tanh, relu in convolutional neural networks

Analyze the emotional elements contained in intelligent sweeping robot

Evolution of ape counseling technology: helping teaching and learning conceive future schools

Transformer -- Analysis and application of attention model

Introduction to testcafe

go-zero单体服务使用泛型简化注册Handler路由
随机推荐
RT_ Use of thread mailbox
What SaaS architecture design do you need to know?
这种动态规划你见过吗——状态机动态规划之股票问题(中)
Automated test tool playwright (quick start)
HDU 3585 maximum shortest distance
Interview fraud: there are companies that make money from interviews
Histogram of pyplot module of Matplotlib (hist(): basic parameter, return value)
HDU 3666 the matrix problemdifferential constraint + stack optimization SPFA negative ring
FreeRTOS个人笔记-任务通知
Easycvr Video Square snapshot adding device channel offline reason display
Method of converting UI file to py file
RT based_ Distributed wireless temperature monitoring system based on thread
Online sql to XML tool
阿里怎么用DDD来拆分微服务?
Activation functions sigmoid, tanh, relu in convolutional neural networks
The default isolation level of MySQL is RR. Why does Alibaba and other large manufacturers change to RC?
【ARXIV2203】CMX: Cross-Modal Fusion for RGB-X Semantic Segmentation with Transformers
HDU 1530 maximum clique
Know etcd
Configuration experiment of building virtual private network based on MPLS