我不写代码 , 我只是代码的搬运工!
官方网址请点击这里
使用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);
}
}];
}