cocopods
pod ‘mob_sharesdk’
pod ‘ReactiveObjC’
AppDelegate.m
导头文件 oneViewController.h
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[oneViewController new]];
oneViewController.h
@property (weak, nonatomic) IBOutlet UITextField *text1;
@property (weak, nonatomic) IBOutlet UITextField *text2;
@property (weak, nonatomic) IBOutlet UIButton *btn1;
@property (weak, nonatomic) IBOutlet UIButton *btn2;
oneViewController.m
#import <ShareSDK/ShareSDK.h>
#import “UIButton+Count.h”
#import “NetRequestManager.h”
#import “ShowAlert.h”
#import “AppCheckOut.h”
#import <ReactiveObjC.h>
#define APPWeak(object) __weak typeof(object) weak##object = object;
@interface oneViewController ()
@end
@implementation oneViewController
-
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.APPWeak(self);
//1.获取验证码:
[[_btn1 rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {//(1)、判断手机号是否为空: if ([weakself.text1.text isEqualToString:@""]) { [ShowAlert showAlterWithMsg:@"手机号不正确" withDely:2]; return ; } //(2)、判断手机号是否正确: BOOL isPhoneNumber = [AppCheckOut checkMobile:weakself.text1.text]; if (!isPhoneNumber) { [ShowAlert showAlterWithMsg:@"手机号格式不正确" withDely:2]; return ; } //(3)、点击获取验证码按钮开始倒计时: [self.btn1 countDownWithTimeInterval:60]; //(4)、根据验证码接口请求验证码: [NetRequestManager requestWithUrl:@"http://buluokes.huimor.com/api" withRequestType:GET postParameters:@{@"method":@"app.passport.sendsms",@"mobile":weakself.text1.text,@"type":@"1",@"user_token":@""} success:^(NSDictionary *resDict) { NSLog(@"=========%@",resDict); } failure:^(NSError *error) { NSLog(@"======%@",error); }];
}];
//2、根据登录接口点击登录按钮
[[_btn2 rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
//(1)非空
if ([weakself.text2.text isEqualToString:@""]) {
[ShowAlert showAlterWithMsg:@“请填入已经发送的验证码” withDely:2];
return ;
}//(2)、正则验证; BOOL isCodeNumber = [AppCheckOut checkSecurityCode:weakself.text2.text]; if (!isCodeNumber) { [ShowAlert showAlterWithMsg:@"验证码不符合规范" withDely:2]; return ; } //(3)、调用登录接口: [self login];
}];
[[self.text1 rac_textSignal]subscribeNext:^(NSString * _Nullable x) {
//两个都为空:
if (![weakself.text2.text isEqualToString:@""] && ![x isEqualToString:@""]) {
weakself.btn2.enabled = YES;
weakself.btn2.backgroundColor = [UIColor blueColor];
}else{
weakself.btn2.enabled = NO;
weakself.btn2.backgroundColor = [UIColor cyanColor];
}}];
[[self.text2 rac_textSignal]subscribeNext:^(NSString * _Nullable x) {
//两个都为空:
if (![weakself.text1.text isEqualToString:@""] && ![x isEqualToString:@""]) {
weakself.btn2.enabled = YES;
weakself.btn2.backgroundColor = [UIColor blueColor];
}else{
weakself.btn2.enabled = NO;
weakself.btn2.backgroundColor = [UIColor cyanColor];
}
}];
} -
(void)login{
APPWeak(self);
NSDictionary *loginDic = @{@“method”?“app.passport.login”,@“mobile”:weakself.text1.text,@“code”:self.text2.text,@“device”?“ios”,@“device_id”?“123123123123”,@“parent_id”?“1”,@“registration_id”?"",@“user_token”?""};
[NetRequestManager requestWithUrl:@“http://buluokes.huimor.com/api” withRequestType:GET postParameters:loginDic success:^(NSDictionary *resDict) {
NSLog(@"+++++++++%@",resDict);
} failure:^(NSError *error) {}];
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end