用Mob提供的免费短信验证码SDK,使得移动APP快速拥有手机注册功能,并且实现短信验证功能和匹配通讯录好友功能。
第一步 获取短信SDK---请到Mob官网下载最新版本的短信验证码SDK,下载回来后解压,可以看到下面的文件结构)其中SMS_SDK.framework 为依赖库文件 SMS_SDKDemo 为示例demo ,其中保存了短信SDK的演示项目代码。
第二步 导入SDK--- 短信SDK 使用如下方式完成集成。具体步骤如下: 将SMS_SDK.framework 文件 直接拖入项目中
第三步 添加依赖库文件SMS_SDK.framework
第四步 注册Mob账号,获取APP Key ,APP Secret
第五步 导入头文件
#import <SMS_SDK/SMSSDK.h>
#import <SMS_SDK/Extend/SMSSDK+AddressBookMethods.h>
第六步 在appDelegate的didFinishLaunchingWithOptions中
//短信验证
//初始化应用,appKey和appSecret从后台申请得
[SMSSDK registerApp:@""
withSecret:@""];
第七步 在获取短信验证码点击方法中
[SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:_shoujihao.text zone:@"86" customIdentifier:nil result:^(NSError *error) {
if (!error) {
NSLog(@"获取验证码成功");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示信息" message:@"已帮您获取验证码" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
[alert show];
}
else{
NSLog(@"错误信息%@", error);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示信息" message:@"请输入正确的电话号码" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
[alert show];
}
}];
第八步 点击登录的点击方法中 判断是否验证成功
[SMSSDK commitVerificationCode:_yanzheng.text phoneNumber:_shoujihao.text zone:@"86" result:^(NSError *error) {
if (!error) {
NSLog(@"验证成功");
// UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示信息" message:@"验证成功" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
// [alert show];
[self.navigationController popToRootViewControllerAnimated:YES];
}
else{
NSLog(@"错误信息:%@", error);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示信息" message:@"您输入的验证码有误" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
[alert show];
}
}];