iOS 短信验证

//1.Mob官网注册 SMSSDK官网公共key

#define appkey @"f3fc6baa9ac4"

#define app_secrect @"7f3dedcb36d92deebcb373af921d635a"

//2.注册key / 注册秘钥(AppdelegateDidFinish)  
    [SMSSDK registerApp:appkey withSecret:app_secrect];
// 是否允许访问通讯录   
    [SMSSDK enableAppContactFriends:NO];

//3.短信验证:

//3.1发送验证
   [SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:self.phoneTextField.text zone:@"86" customIdentifier:nil result:^(NSError *error) {
        if (error) {
            NSLog(@"获取短信验证码失败:%@",error);
        }else{
            NSLog(@"获取短信验证码成功");
            self.phoneNum = self.phoneTextField.text;
        }
    }];

//3.2验证
- (IBAction)commitVerifyCode {
       [SMSSDK commitVerificationCode:self.verifyCodeTextField.text phoneNumber:self.phoneNum zone:@"86" result:^(NSError *error) {
        if (error) {
            NSLog(@"验证失败");
        }else{
            NSLog(@"验证成功");
        }
    }];

条件,导入两个框架 :
1.MOBFoundation_IDFA
2.SMSSDK

导入依赖库:

iOS 短信验证_第1张图片
Snip20160920_1.png

文本短信的方式获取验证码 响应结果枚举

[SMSSDKUI showVerificationCodeViewWithMetohd:SMSGetCodeMethodSMS result:^(enum SMSUIResponseState state,NSString *phoneNumber,NSString *zone, NSError *error) {

}];

你可能感兴趣的:(iOS 短信验证)