您的位置:首页 > 其它

友盟短信验证 SMS_SDK 的使用

2015-10-08 21:33 761 查看
相信大家在写登录注册时会经常用到短信验证,我所用的是友盟的短信验证,但是官方的demo写的很乱,有很多都用不到。

第一步:去友盟官网生成 appKey
AppSceret,然后在appDelegate 里 写上短信注册代码:[SMS_SDK registerApp:appKey withSecret:AppSceret];

第二部:导入 SMS_SDK 包。

第三部:在代码中使用,其实主要就三个方法,其他根据需要在选择用。

1. 获取验证码

+ (void)getVerificationCodeBySMSWithPhone:(NSString *)phoneNumber

                                     zone:(NSString *)zone

                                   result:(GetVerificationCodeResultHandler)result;

  zone 是国内的话可以默认写成 "86";

 例: NSString *str = @"86";

    

    [SMS_SDK getVerificationCodeBySMSWithPhone:self.phoneField.text zone:str result:^(SMS_SDKError *error) {

        

        if (!error) {

            

            [MBProgressHUD showSuccess:@"正在发送验证码"];

            

        }else{

            

            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请输入正确手机号" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

            

            [alertView show];

            

        }

        

    }];

2. 提交验证码并请求验证结果

+(void)commitVerifyCode:(NSString *)code

                 result:(CommitVerifyCodeBlock)result;

例: [SMS_SDK commitVerifyCode:self.YZMtextField.text result:^(enum SMS_ResponseState state) {

        

        if (1 == state ) {

            

            [self loadRegister1];

            

            

            

        } else if(0 == state){

            

            

            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您输入的验证码不正确" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

            

            [alertView show];

            

        }

        

    }];

请求结果1代表成功,0代表验证码出错。

其他的一些方法,比如获取通讯录好友什么的可以根据需求在demo找。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息