ios開發(fā)--手機(jī)驗(yàn)證碼驗(yàn)證(SMSsdk)

                             美圖鎮(zhèn)樓
11150073,1366,768.jpg

首先這里使用的是SMSsdk短信驗(yàn)證,如果用其他的更換即可

下面是點(diǎn)擊按鈕的事件,其中倒計(jì)時有點(diǎn)擊后的小動畫,自己去體會吧
<code>
-(void)SendCodeBut:(UIButton *)button{
if([self.MobileText.text compare:@""]==NSOrderedSame){
UIAlertView *alertV = [[UIAlertView alloc]initWithTitle:@"提示" message:@"手機(jī)號碼不能為空" delegate:self cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];
[alertV show];
</code>

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

<code>
UIAlertView alertV = [[UIAlertView alloc]initWithTitle:@"提示" message:@"手機(jī)號碼格式有誤,請輸入正確的號碼" delegate:self cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];
[alertV show];
</code>
//手機(jī)號輸入正常,發(fā)送驗(yàn)證碼并且啟動倒計(jì)時功能
}else if(_MobileText.text.length==11){
/
*

  • @from v1.1.1

  • @brief 獲取驗(yàn)證碼(Get verification code)

  • @param method 獲取驗(yàn)證碼的方法(The method of getting verificationCode)

  • @param phoneNumber 電話號碼(The phone number)

  • @param zone 區(qū)域號,不要加"+"號(Area code)

  • @param result 請求結(jié)果回調(diào)(Results of the request)

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

NSLog(@"sada提交手機(jī)成功%@",error);

}else{

NSLog(@"sada提交手機(jī)成功");
<code>
__block int timeout=60; //倒計(jì)時時間
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); //每秒執(zhí)行

dispatch_source_set_event_handler(_timer, ^{

if(timeout<=0){ //倒計(jì)時結(jié)束,關(guān)閉

dispatch_source_cancel(_timer);

dispatch_async(dispatch_get_main_queue(), ^{

//設(shè)置界面的按鈕顯示 根據(jù)自己需求設(shè)置

[_sendCodeButton setTitle:@"發(fā)送驗(yàn)證碼" forState:UIControlStateNormal];

_sendCodeButton.userInteractionEnabled = YES;

});

}
</code>
else{
<code>
int seconds = timeout % 60;

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

dispatch_async(dispatch_get_main_queue(), ^{

//設(shè)置界面的按鈕顯示 根據(jù)自己需求設(shè)置

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

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:1];

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

//文字自適應(yīng)

[_sendCodeButton sizeToFit];

[UIView commitAnimations];

_sendCodeButton.userInteractionEnabled = NO;

});

timeout--;

}

});

dispatch_resume(_timer);

}

}];

}

}
</code>

                              福利來啦

性感風(fēng)


11382286,1366,768.jpg
![ ![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)

清新風(fēng)

14004029,1366,768.jpg
11454588,1366,768.jpg
14002997,1366,768.jpg
13971598,1366,768.jpg
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容