Mob免费短信验证

<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];
            }
    }];
    
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,198评论 4 61
  • 1. 清晨五点半,她关掉手机闹钟起床,洗漱、化妆、挑选合适的衣服......今天有两家面试,离学校很远,跨越市中心...
    小有change阅读 233评论 0 0
  • 记得在我很小的时候,那时尚未念书。每逢过年时节爷爷亲娘(无锡话里“奶奶”的叫法)总会带着我回农村。在农村有座宅子,...
    晚春诗阅读 282评论 0 0
  • 有哥们问:“哎呀,客户邀约来了,是一位高冷的大美女,所以在交谈的过程中,总是放不开,不自然,感觉好难啊,有什么办法...
    李葳蕤阅读 332评论 0 0