本文挡适用于iOS短信SDK v1.0.0 接入的指导,用于指导SDK的使用方法,默认读者熟悉Xcode编译器的使用以及iOS编程语言。
应用的创建流程及APPID的获取,请查看「账号创建」文档
注意:如果应用有多个包名或签名不同的马甲包,须创建多个对应包名和签名的应用,否则包名或签名将校验不通过。
1、下载SDK 以及demo体验包
2、将申请的应用的bundleId 以及 对应 appid 填入demo
3、应需要发送的短信模板 填入发送短信的api 中
将CLCore.framework、CLSMS.framework一起拖入项目中(注意勾选Copy items if needed)
OtherLinkerFlags中配置:xcode->BuildSetting->Other Linker Flags 添加 -ObjC
在使用SDK时,请先初始化SDK,建议在app 启动时初始化SDK。方法原型
/// SDK初始化
/// @param appid 在SDK平台创建应用成功后,分配的appid
+ (void)initWithAppid:(NSString *)appid;
参数说明
参数 | 类型 | 说明 |
---|---|---|
appid | NSString * | 应用的appid |
调用示例
#import <CLCore/CLCore.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
...
v1.0.0.0版本:
[CLCoreManager initWithAppid:@"appid"];
v1.0.0.1及以后版本:
[CLCoreManager initWithAppkey:@"appkey"];
...
return YES;
}
方法原型
/// 发送验证验
/// @param phoneNumber 手机号
/// @param templateId 模板id
/// @param success 发送短信成功 返回messigeId
/// @param faild 发送短信失败 result 服务器信息,error 网络错误信息
+(void)getVerificationCodePhoneNumber:(NSString *)phoneNumber
templateId:(NSString *)templateId
success:(void (^)(NSString *messageId))success
faild:(void (^)(NSDictionary*_Nullable result, NSError * _Nullable error))faild;
参数说明
参数 | 类型 | 说明 |
---|---|---|
phoneNumber | NSString * | 接收短信的手机号码 |
templateId | NSString * | 短信的模板ID |
success | Block | 短信发送成功回调 |
faild | Block | 短信发送失败回调(NSDictionary *业务错误信息,NSError,网络错误信息) |
调用示例
#import <CLSMS/CLSMS.h>
[CLSMSManager getVerificationCodePhoneNumber:@"手机号" templateId:@"模板id" success:^(NSString * _Nonnull messageId) {
dispatch_async(dispatch_get_main_queue(), ^{
[SVProgressHUD showInfoWithStatus:@"验证码发送成功"];
sender.backgroundColor = UIColor.lightGrayColor;
sender.userInteractionEnabled = YES;
[self startGCDTimer:sender];
});
} faild:^(NSDictionary * _Nonnull result, NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (result) {
[SVProgressHUD showErrorWithStatus:result[@"msg"]];
}else{
NSLog(@"error = %@",error);
[SVProgressHUD showErrorWithStatus:error.domain];
}
});
}];
方法原型
/// 验证验证码
/// @param phoneNumber 手机号
/// @param templateId 模板id
/// @param code 验证码
/// @param success 验证成功
/// @param faild 验证失败
+(void)commitVerificationCodePhoneNumber:(NSString *)phoneNumber
templateId:(NSString *)templateId
code:(NSString *)code
success:(void (^)(NSString *message))success
faild:(void (^)(NSDictionary*_Nullable result, NSError * _Nullable error))faild;
参数说明
参数 | 类型 | 说明 |
---|---|---|
phoneNumber | NSString * | 手机号 |
templateId | NSString * | 模板id |
code | NSString * | 验证码 |
success | Block | 成功回调 |
faild | Block | 失败回调 (NSDictionary *业务错误信息,NSError,网络错误信息) |
调用示例
[CLSMSManager commitVerificationCodePhoneNumber:@"手机号" templateId:@"模板id" code:@"验证码" success:^(NSString * _Nonnull message) {
dispatch_async(dispatch_get_main_queue(), ^{
[SVProgressHUD showInfoWithStatus:@"验证码验证成功"];
});
} faild:^(NSDictionary * _Nullable result, NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (result) {
[SVProgressHUD showErrorWithStatus:result[@"msg"]];
}else{
NSLog(@"error = %@",error);
[SVProgressHUD showErrorWithStatus:error.domain];
}
});
}];
方法原型
/// 生物识别类型检测,判断设备支持哪种认证方式
- (CLFaceIDDeviceSupportState )clBiometricsTypeCheck;
返回值及说明
参数 | 类型 | 说明 |
---|---|---|
CLFaceIDDeviceSupportState | 枚举 | 当前机型生物识别状态 |
枚举值说明
typedef NS_ENUM(NSInteger, CLFaceIDDeviceSupportState) {
/**
* 设备不支持生物验证
*/
CLFaceIDDeviceSupportStateNotAvailable =0,
/**
* 设备支持生物验证 但尚未未设置
*/
CLFaceIDDeviceSupportStateNotEnrolled,
/**
* 识别错误次数过多 被锁定(需要重新输入手机密码解锁后才可以使用)
*/
CLFaceIDDeviceSupportStateLockout,
/**
* 设备支持TouchID验证
*/
CLFaceIDDeviceSupportStateTouchID,
/**
* 设备支持FaceID验证
*/
CLFaceIDDeviceSupportStateFaceID,
};
调用示例
CLFaceIDDeviceSupportState state = CLFingerprintVerifyManager.shareInstance.clBiometricsTypeCheck;
if (state == CLFaceIDDeviceSupportStateTouchID || state == CLFaceIDDeviceSupportStateFaceID) {
//生物识别可用
}
方法原型
/// 判断该账户是否绑定过 生物识别
/// @param userId 账号信息(每个账户唯一)
- (BOOL)isBoundFingerprint:(NSString *)userId;
参数说明
参数 | 类型 | 说明 |
---|---|---|
userId | NSString * | 与用户对应唯一,建议使用userid |
调用示例
BOOL isBound = [CLFingerprintVerifyManager.shareInstance isBoundFingerprint:@"userid"];
if (isBound) {
//可以验证验证
}else{
//可以进行绑定
}
方法原型
/// 生物识别 绑定/验证
/// @param faceIDAuthType 业务类型
/// @param userId 账号信息
/// @param desc 业务描述
/// @param complete 回调信息
- (void)clStartAuthWithCLFaceIDAuthType:(CLFaceIDAuthType )faceIDAuthType
userId:(NSString *)userId
description:(NSString *)desc
complete:(void (^) (BOOL success ,NSError *error))complete;
参数说明
参数 | 类型 | 说明 |
---|---|---|
faceIDAuthType | 枚举 | 业务类型 绑定/验证 |
userId | NSString * | 与用户对应唯一,建议使用userid |
desc | NSString * | 生物识别展示系统页面时 的提示语 |
complete | Block | 生物识别结果 success 是否成功 error 具体错误 |
调用示例
绑定
[[CLFingerprintVerifyManager shareInstance] clStartAuthWithCLFaceIDAuthType:CLFaceIDAuthTypeBound userId:@"11" description:@"" complete:^(BOOL success, NSError * _Nonnull error) {
if (success) {
[SVProgressHUD setInfoImage:nil];
[SVProgressHUD showInfoWithStatus:@"绑定成功"];
}else{
[SVProgressHUD showErrorWithStatus:error.domain];
}
}];
验证
[[CLFingerprintVerifyManager shareInstance] clStartAuthWithCLFaceIDAuthType:CLFaceIDAuthTypeAuth userId:@"11" description:@"" complete:^(BOOL success, NSError * _Nonnull error) {
if (success) {
[SVProgressHUD setInfoImage:nil];
[SVProgressHUD showInfoWithStatus:@"验证成功"];
}else{
[SVProgressHUD showErrorWithStatus:error.domain];
}
}];