iOS 基础:MOB短信验证码


下载,使用说明有官网文档。
在这里插入图片描述

下载

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

appKey and appSerect

注意这一步浏览器要关闭收藏栏,才能看到左边的栏,兰旗

使用

将SDK文件夹拖动到过程中
在这里插入图片描述
添加一些库:
在这里插入图片描述
配置:
在这里插入图片描述

函数说明

#pragma mark - 支持获取验证码和提交验证码 (get the verification code and commit verifacation code)
/**
 *  @from                    v1.1.1
 *  @brief                   获取验证码(Get verification code)
 *
 *  @param method            获取验证码的方法(The method of getting verificationCode)
 *  @param phoneNumber       电话号码(The phone number)
 *  @param zone              区域号,不要加"+"号(Area code)
 *  @param result            请求结果回调(Results of the request)
 */
+ (void) getVerificationCodeByMethod:(SMSGetCodeMethod)method
                         phoneNumber:(NSString *)phoneNumber
                                zone:(NSString *)zone
                              result:(SMSGetCodeResultHandler)result __deprecated_msg("deprecated from v3.1.0");

/**
 *  @from                    v3.1.0
 *  @brief                   获取验证码(Get verification code)
 *
 *  @param method            获取验证码的方法(The method of getting verificationCode)
 *  @param phoneNumber       电话号码(The phone number)
 *  @param zone              区域号,不要加"+"号(Area code)
 *  @param tmpCode           模板id(template id)
 *  @param result            请求结果回调(Results of the request)
 */
+ (void) getVerificationCodeByMethod:(SMSGetCodeMethod)method
                         phoneNumber:(NSString *)phoneNumber
                                zone:(NSString *)zone
                            template:(NSString *)tmpCode
                              result:(SMSGetCodeResultHandler)result;


/**
 * @from                    v1.1.1
 * @brief                   提交验证码(Commit the verification code)
 *
 * @param code              验证码(Verification code)
 * @param phoneNumber       电话号码(The phone number)
 * @param zone              区域号,不要加"+"号(Area code)
 * @param result            请求结果回调(Results of the request)
 */
+ (void) commitVerificationCode:(NSString *)code
                    phoneNumber:(NSString *)phoneNumber
                           zone:(NSString *)zone
                         result:(SMSCommitCodeResultHandler)result;
/**
 * @from                    v2.0.1
 * @return                  返回SDK版本号(Return the version number of this SDK)
 */
+ (NSString *) sdkVersion;

/**
 * @from         v1.1.1
 * @brief        获取区号(Get the Area code of the country)
 *
 * @param result 请求结果回调(Results of the request)
 */
+ (void) getCountryZone:(SMSGetZoneResultHandler)result;

typedef NS_ENUM(NSUInteger, SMSGetCodeMethod)
{
    SMSGetCodeMethodSMS = 0,  //文本短信方式
    SMSGetCodeMethodVoice = 1 //语音方式
};

zone国家码:中国是86;

代码使用

在这里插入图片描述

//
//  ViewController.m
//  SMSSDK
//
//  Created by  on 2019/7/1.
//  Copyright © 2019 Shae. All rights reserved.
//

#import "ViewController.h"
#import "SMS_SDK/SMSSDK.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *phoneNumber;
@property (weak, nonatomic) IBOutlet UITextField *codeNumber;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}
//提示弹窗格式
//UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:errorMsg preferredStyle:UIAlertControllerStyleAlert];
//[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
// 弹出对话框
//[self presentViewController:alert animated:true completion:nil];
//获取验证码
- (IBAction)clickGetSMS:(UIButton *)sender {
    NSString *phoneNUmber=self.phoneNumber.text;
    [SMSSDK getVerificationCodeByMethod: SMSGetCodeMethodSMS phoneNumber:phoneNUmber zone:@"86" template:nil result:^(NSError *error) {
        if (error==nil) {
            UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"发送验证码成功" message:nil preferredStyle:UIAlertControllerStyleAlert];
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
            [self presentViewController:alert animated:true completion:nil];
        }else{
            UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"发送验证码失败" message:[NSString stringWithFormat:@"%@",[error.userInfo objectForKey:@"description"]] preferredStyle:UIAlertControllerStyleAlert];
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
            [self presentViewController:alert animated:true completion:nil];
        }
       
    }];
}
//验证验证码
- (IBAction)clickedVerifyButton:(UIButton *)sender {
    NSString *codeNumber=self.codeNumber.text;
    NSString *phoneNUmber=self.phoneNumber.text;
    [SMSSDK commitVerificationCode:codeNumber phoneNumber:phoneNUmber zone:@"86" result:^(NSError *error) {
        if (error==nil) {
            UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"验证成功" message:nil preferredStyle:UIAlertControllerStyleAlert];
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
            [self presentViewController:alert animated:true completion:nil];
        }else{
            UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"验证失败" message:[NSString stringWithFormat:@"%@",[error.userInfo objectForKey:@"description"]] preferredStyle:UIAlertControllerStyleAlert];
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
            [self presentViewController:alert animated:true completion:nil];
        }
    }];
}

@end


















在这里插入图片描述
注意:运营商决定,每个手机号,每天只能接受5条验证码。
代码:https://github.com/ShaeZhuJiu/SMSSDK_base.git

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值