短信验证码

我不写代码 , 我只是代码的搬运工!
官方网址请点击这里
使用cocoapods集成方式

target 'SMSSDK' do
pod 'mob_smssdk'
end

添加SDK所需依赖库 列表:

libz.dylib
libicucore.dylib
MessageUI.framework
JavaScriptCore.framework
libstdc++.dylib (这个库在XCode10之后找不到,已经被废弃,以libc++替代)
注意:在XCode7上面运行报错的话,还需要增加这几个依赖库
SystemConfiguration.framework
CoreTelephony.framework
AdSupport.framework

打开网络授权!
设置MOBAppKey 和 MOBAppSecret
MOBAppKey 和 MOBAppSecret申请在官网
注意!!!
申请完MOBAppKey 和 MOBAppSecret以后
需要设置短信如下
在这里插入图片描述
添加SMSSDK
在这里插入图片描述
打开全球设置
在info.plist中设置
在这里插入图片描述
如图 设置完毕
在ViewController.m中
导入头文件

#import <SMS_SDK/SMSSDK.h>

设置两个UITextField , 一个输入手机号 , 一个输入验证码
设置两个UIButton , 一个获取验证码 , 一个提交验证码
代码部分:

@interface ViewController ()
{
    //手机号的文本框
    UITextField *NumberTextField;
    //验证码的文本框
    UITextField *CodeTextField;
    //发送短信按钮
    UIButton *FSBtn;
    //提交按钮
    UIButton *TJBtn;
}

viewDidLoad内 设置UITextField和UIButton的位置等 和两个按钮的点击方法

//手机号文本框
    NumberTextField = [[UITextField alloc] initWithFrame:CGRectMake(30, 100, 260, 50)];
    NumberTextField.placeholder = @"请输入手机号";
    NumberTextField.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:NumberTextField];
    
    //发送验证码按钮
    FSBtn = [[UIButton alloc] initWithFrame:CGRectMake(30, 200, 260, 50)];
    [FSBtn setTitle:@"发送验证码" forState:UIControlStateNormal];
    [FSBtn setBackgroundColor:[UIColor blueColor]];
    [FSBtn addTarget:self action:@selector(fasong) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:FSBtn];
    
    //验证码文本框
    CodeTextField = [[UITextField alloc] initWithFrame:CGRectMake(30, 300, 260, 50)];
    CodeTextField.placeholder = @"请输入验证码";
    CodeTextField.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:CodeTextField];
    
    //验证验证码按钮
    TJBtn = [[UIButton alloc] initWithFrame:CGRectMake(30, 400, 260, 50)];
    [TJBtn setTitle:@"提交验证码" forState:UIControlStateNormal];
    [TJBtn setBackgroundColor:[UIColor blueColor]];
    [TJBtn addTarget:self action:@selector(tijiao) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:TJBtn];

发送验证码的按钮方法

//发送验证码的按钮方法
- (void)fasong{
    [SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:NumberTextField.text zone:@"86"  result:^(NSError *error) {
        
        if (!error)
        {
            NSLog(@"发送成功");
        }
        else
        {
            NSLog(@"发送失败:///%@",error);
        }
    }];

}

提交验证码的按钮方法

//提交验证码的按钮方法
- (void)tijiao{
    [SMSSDK commitVerificationCode:CodeTextField.text phoneNumber:NumberTextField.text zone:@"86" result:^(NSError *error) {
        
        if (!error)
        {
            NSLog(@"验证成功");
        }
        else
        {
            NSLog(@"验证失败:///%@",error);
        }
    }];
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值