<h1>1.導(dǎo)入SDK以及類庫(kù)</h1>###
libz.dylib
libicucore.dylib
MessageUI.framework
JavaScriptCore.framework
libstdc++.dylib
<h1>2.AppKey</h1>###
//appdelegate里初始化應(yīng)用凭峡,appKey和appSecret從后臺(tái)申請(qǐng)得
[SMSSDK registerApp:APPKEY withSecret:APPSECERT];
<h1>3.點(diǎn)擊獲取驗(yàn)證碼按鈕之后</h1>###
<ol>
<li>先判斷手機(jī)號(hào)</li>
<li>調(diào)用Mod接口</li>
<li>啟動(dòng)定時(shí)器</li>
</ol>
-(void)getValidCode:(UIButton *)sender
{
//將輸入的手機(jī)號(hào)進(jìn)行轉(zhuǎn)換成NSScanner對(duì)象
NSScanner *scan = [NSScanner scannerWithString:_phoneTextFiled.text];
int val;
//掃描 手機(jī)號(hào)是否是數(shù)字類型
BOOL PureInt = [scan scanInt:&val]&&[scan isAtEnd];
if (!PureInt || _phoneTextFiled.text.length !=11)
{
[_phoneTextFiled shake];
}
else
{
/**
* @from v1.1.1
* @brief 獲取驗(yàn)證碼(Get verification code)
*
* @param method 獲取驗(yàn)證碼的方法(The method of getting verificationCode)
* @param phoneNumber 電話號(hào)碼(The phone number)
* @param zone 區(qū)域號(hào)蛹疯,不要加"+"號(hào)(Area code)
* @param customIdentifier 自定義短信模板標(biāo)識(shí) 該標(biāo)識(shí)需從官網(wǎng)http://www.mob.com上申請(qǐng)颠区,審核通過后獲得蛀序。(Custom model of SMS. The identifier can get it from http://www.mob.com when the application had approved)
* @param result 請(qǐng)求結(jié)果回調(diào)(Results of the request)
*/
[SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:_phoneTextFiled.text
zone:@"86"
customIdentifier:nil
result:^(NSError *error){
if (!error) {
NSLog(@"獲取驗(yàn)證碼成功");
} else {
NSLog(@"錯(cuò)誤信息:%@",error);
}}];
_oUserPhoneNum =_phoneTextFiled.text;
//__weak MMZCHMViewController *weakSelf = self;
sender.userInteractionEnabled = YES;
self.timeCount = 60;
self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(reduceTime:) userInfo:sender repeats:YES];
}
}
Timer循環(huán)程序
-(void)reduceTime:(NSTimer *)codeTimer
{
self.timeCount--;
if (self.timeCount == 0) {
[_yzButton setTitle:@"重新獲取驗(yàn)證碼" forState:UIControlStateNormal];
[_yzButton setTitleColor:[UIColor colorWithRed:248/255.0f green:144/255.0f blue:34/255.0f alpha:1] forState:UIControlStateNormal];
UIButton *info = codeTimer.userInfo;
info.enabled = YES;
_yzButton.userInteractionEnabled = YES;
[self.timer invalidate];
} else {
NSString *str = [NSString stringWithFormat:@"%lu秒后重新獲取", self.timeCount];
[_yzButton setTitle:str forState:UIControlStateNormal];
_yzButton.userInteractionEnabled = NO;
}
}
<h1>4.輸入驗(yàn)證碼幻锁,點(diǎn)擊下一步</h1>###
-(void)next:(UIButton *)button
{
[SMSSDK commitVerificationCode:_pwdTextFiled.text phoneNumber:_phoneTextFiled.text zone:@"86" result:^(SMSSDKUserInfo *userInfo, NSError *error) {
if (!error)
{
//頁(yè)面跳轉(zhuǎn)
NSLog(@"成功");
}
else
{
NSLog(@"錯(cuò)誤信息:%@",error);
[_pwdTextFiled shake];
[_phoneTextFiled shake];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"請(qǐng)輸入正確的手機(jī)號(hào)碼和驗(yàn)證碼" message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleCancel handler:nil];
[alert addAction:action];
[self presentViewController:alert animated:YES completion:nil];
}
}];
}