下载,使用说明有官网文档。
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/cb4c28a6a90729f72dbc2e2a5123b4ee.png)
下载
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