iOS短信验证

用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];
        }
    }];



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值