ios开发--手机验证码验证(SMSsdk)

                             美图镇楼
ios开发--手机验证码验证(SMSsdk)_第1张图片
11150073,1366,768.jpg

首先这里使用的是SMSsdk短信验证,如果用其他的更换即可

下面是点击按钮的事件,其中倒计时有点击后的小动画,自己去体会吧

-(void)SendCodeBut:(UIButton *)button{
if([self.MobileText.text compare:@""]==NSOrderedSame){
UIAlertView *alertV = [[UIAlertView alloc]initWithTitle:@"提示" message:@"手机号码不能为空" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alertV show];

}else if(_MobileText.text.length<11){


UIAlertView alertV = [[UIAlertView alloc]initWithTitle:@"提示" message:@"手机号码格式有误,请输入正确的号码" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alertV show];

//手机号输入正常,发送验证码并且启动倒计时功能
}else if(_MobileText.text.length==11){
/
*

  • @from v1.1.1

  • @brief 获取验证码(Get verification code)

  • @param method 获取验证码的方法(The method of getting verificationCode)

  • @param phoneNumber 电话号码(The phone number)

  • @param zone 区域号,不要加"+"号(Area code)

  • @param result 请求结果回调(Results of the request)

*/

[SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:self.MobileText.text zone:@"86" customIdentifier:nil result:^(NSError *error) {

if (error) {

NSLog(@"sada提交手机成功%@",error);

}else{

NSLog(@"sada提交手机成功");

__block int timeout=60; //倒计时时间
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);

dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行

dispatch_source_set_event_handler(_timer, ^{

if(timeout<=0){ //倒计时结束,关闭

dispatch_source_cancel(_timer);

dispatch_async(dispatch_get_main_queue(), ^{

//设置界面的按钮显示 根据自己需求设置

[_sendCodeButton setTitle:@"发送验证码" forState:UIControlStateNormal];

_sendCodeButton.userInteractionEnabled = YES;

});

}

else{

int seconds = timeout % 60;

NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];

dispatch_async(dispatch_get_main_queue(), ^{

//设置界面的按钮显示 根据自己需求设置

//NSLog(@"____%@",strTime);

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:1];

[_sendCodeButton setTitle:[NSString stringWithFormat:@"重新发送(%@)",strTime] forState:UIControlStateNormal];

//文字自适应

[_sendCodeButton sizeToFit];

[UIView commitAnimations];

_sendCodeButton.userInteractionEnabled = NO;

});

timeout--;

}

});

dispatch_resume(_timer);

}

}];

}

}

                              福利来啦

性感风


ios开发--手机验证码验证(SMSsdk)_第2张图片
11382286,1366,768.jpg
ios开发--手机验证码验证(SMSsdk)_第3张图片
![ ![11857619,1366,768.jpg](http://upload-images.jianshu.io/upload_images/1491655-322ff25b7af269e5.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) ](http://upload-images.jianshu.io/upload_images/1491655-979fe8daac712627.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

清新风

ios开发--手机验证码验证(SMSsdk)_第4张图片
14004029,1366,768.jpg
ios开发--手机验证码验证(SMSsdk)_第5张图片
11454588,1366,768.jpg
ios开发--手机验证码验证(SMSsdk)_第6张图片
14002997,1366,768.jpg
ios开发--手机验证码验证(SMSsdk)_第7张图片
13971598,1366,768.jpg

你可能感兴趣的:(ios开发--手机验证码验证(SMSsdk))