<h1>1.导入SDK以及类库</h1>###
libz.dylib
libicucore.dylib
MessageUI.framework
JavaScriptCore.framework
libstdc++.dylib
<h1>2.AppKey</h1>###
//appdelegate里初始化应用,appKey和appSecret从后台申请得
[SMSSDK registerApp:APPKEY withSecret:APPSECERT];
<h1>3.点击获取验证码按钮之后</h1>###
<ol>
<li>先判断手机号</li>
<li>调用Mod接口</li>
<li>启动定时器</li>
</ol>
-(void)getValidCode:(UIButton *)sender
{
//将输入的手机号进行转换成NSScanner对象
NSScanner *scan = [NSScanner scannerWithString:_phoneTextFiled.text];
int val;
//扫描 手机号是否是数字类型
BOOL PureInt = [scan scanInt:&val]&&[scan isAtEnd];
if (!PureInt || _phoneTextFiled.text.length !=11)
{
[_phoneTextFiled shake];
}
else
{
/**
* @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 customIdentifier 自定义短信模板标识 该标识需从官网http://www.mob.com上申请,审核通过后获得。(Custom model of SMS. The identifier can get it from http://www.mob.com when the application had approved)
* @param result 请求结果回调(Results of the request)
*/
[SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:_phoneTextFiled.text
zone:@"86"
customIdentifier:nil
result:^(NSError *error){
if (!error) {
NSLog(@"获取验证码成功");
} else {
NSLog(@"错误信息:%@",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循环程序
-(void)reduceTime:(NSTimer *)codeTimer
{
self.timeCount--;
if (self.timeCount == 0) {
[_yzButton setTitle:@"重新获取验证码" 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.输入验证码,点击下一步</h1>###
-(void)next:(UIButton *)button
{
[SMSSDK commitVerificationCode:_pwdTextFiled.text phoneNumber:_phoneTextFiled.text zone:@"86" result:^(SMSSDKUserInfo *userInfo, NSError *error) {
if (!error)
{
//页面跳转
NSLog(@"成功");
}
else
{
NSLog(@"错误信息:%@",error);
[_pwdTextFiled shake];
[_phoneTextFiled shake];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"请输入正确的手机号码和验证码" message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil];
[alert addAction:action];
[self presentViewController:alert animated:YES completion:nil];
}
}];
}