DID SDK [使用文档]
一、安装
因为SDK目前尚未发布至GitHub,目前只支持手动安装。
手动安装:
-
将 DIDSDK.framework 和DIDSDKBundle.bundle文件拷贝到项目中。
-
进入你的项目,选择
Add files to Your Project Name
。 -
导入 DIDSDK。
in Swift
import DIDSDK
in Objective-C
#import <DIDSDK/DIDSDK.h>
二、使用
SDK权限设置:
1、打开info.plist,添加Application supports iTunes file sharing,设置为NO
2、打开info.plist,添加View controller-based status bar appearance,设置为YES
3、打开info.plist,添加Privacy - Microphone Usage Description
4、打开info.plist,添加Privacy - Camera Usage Description
SDK版本要求:
[iOS 11] && [iOS 11 +]
SDK注册:
进入AppDelegate.m中注册SDK:
objective-c
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSString *clientId = @"your clientId";
NSString *clientKey = @"your clientKey";
NSString *phoneNumber = @"your phoneNumber";
NSString *phoneCountryCode = @"your phoneCountryCode";
[DIDSDKManager.shared registerSDKWithClientId:clientId clientKey:clientKey phoneCountryCode:phoneCountryCode phoneNumber:phoneNumber resultBlock:^(ResultErrorType type, NSString * msg) {
NSLog(@"注册结果:%@", msg);
}];
}
当注册回调中,ResultErrorType 为RESULTTYPE_SUCCESS_REGISTER 时,代表注册成功,更多类型可以查看DIDSDKManagerDefine.h
。
注意: 在使用SDK前,请务必保证在SDK注册成功后,否则将无法正常使用.
开始认证:
当您需要使用SDK的认证服务时:
objective-c
[[DIDSDKManager shared] startServiceFromeNavi:self.navigationController resultBlock:^(NSString * _Nonnull accessToken) {
// save the accessToken on your project
// use the accessToken...
}];
当您需要使用SDK的Open API服务时:
您可以导入#import <DIDSDK/DIDNetManager+Post.h>
,并查看DIDNetManager+Post.h中的请求方法。
请求回调定义:
objective-c
/// 数据请求回调
typedef void (^RequestCompleteServiceBlock)(NSDictionary *dic);
typedef void (^RequestErrorServiceBlock)(NSError *error);
请求方法定义:
objective-c
/// 发送短信验证码
/// - Parameters:
/// - phoneNumber: 手机号
/// - phoneCountryCode: 手机所属区
/// - channel: 发送方式
+(void)sendSmsMessagingWithPhoneNumber:(NSString *)phoneNumber
phoneCountryCode:(NSString *)phoneCountryCode
channel:(SMSChannel)channel
completeBlock:(RequestCompleteServiceBlock)successBlock
errorBlock:(RequestErrorServiceBlock)errorBlock;
/// 根据人脸获取AccessToken
/// - Parameters:
/// - portraitImage: 人脸图片base64字符串
/// - verifyMethod: 认证方式
/// - block: 回调
+(void)getAccessTokenByFacePortraitImage:(NSString *)portraitImage
verifyMethod:(VerifyMethod)verifyMethod
completeBlock:(RequestCompleteServiceBlock)successBlock
errorBlock:(RequestErrorServiceBlock)errorBlock;
/// 根据email 或者mobile 获取AccessToken
/// - Parameters:
/// - email: email description
/// - password: password description
/// - phoneNumber: phoneNumber description
/// - phoneCountryCode: phoneCountryCode description
/// - phonePassCode: phonePassCode description
/// - verifyMethod: 认证方式
/// - block: 回调
+(void)getAccessTokenByEmailOrMobileWithEmail:(NSString *)email
password:(NSString *)password
phoneNumber:(NSString *)phoneNumber
phoneCountryCode:(NSString *)phoneCountryCode
phonePassCode:(NSString * )phonePassCode
verifyMethod:(VerifyMethod)verifyMethod
completeBlock:(RequestCompleteServiceBlock)successBlock
errorBlock:(RequestErrorServiceBlock)errorBlock;
/// User Inquiry
/// 查询did账号的信息
/// - block: 回调
+(void)getAccountWithCompleteBlock:(RequestCompleteServiceBlock)successBlock
errorBlock:(RequestErrorServiceBlock)errorBlock;
/// User phone number modification
/// 修改手机号
/// - Parameters:
/// - newPhoneNumber: 新手加号
/// - newPhonePassCode: 新手机号验证码
/// - newPhoneCountryCode: 手机区号
/// - block: 回调
+(void)modificationUserPhoneNumberWithNewPhoneNumber:(NSString *)newPhoneNumber
newPhonePassCode:(NSString *)newPhonePassCode
newPhoneCountryCode:(NSString *)newPhoneCountryCode
completeBlock:(RequestCompleteServiceBlock)successBlock
errorBlock:(RequestErrorServiceBlock)errorBlock;
/// User attribute modification
/// 修改did账号的信息
/// - Parameters:
/// - userName: 昵称
/// - familyName: 姓
/// - middleName: 中间名
/// - givenName: 名
/// - avatarImage: 头像
/// - portraitImage: 人脸底图
/// - idType: ID类型
/// - idNumber: ID账号
/// - birthday: 生日,格式为yyyy-MM-dd
/// - gender: 性别
/// - company: 所在公司
/// - address: 所处地址
/// - block: 回调
+(void)modificationUserAttributeWithUserName:(NSString *)userName
familyName:(NSString *)familyName
middleName:(NSString *)middleName
givenName:(NSString *)givenName
avatarImage:(NSString *)avatarImage
portraitImage:(NSString *)portraitImage
idType:(IdType)idType
idNumber:(NSString *)idNumber
birthday:(NSString *)birthday
gender:(GenderType)gender
company:(NSString *)company
address:(NSString *)address
completeBlock:(RequestCompleteServiceBlock)successBlock
errorBlock:(RequestErrorServiceBlock)errorBlock;
/// User registration
/// 用户注册
/// - Parameters:
/// - passCode: 一次性临时验证码,你需要先调用发送短信或者发送邮件接口获取验证码。目前仅支持手机验证
/// - email: 邮箱
/// - phoneCountryCode: 手机区号,默认沙特手机号可不填
/// - givenName: 名
/// - userName: 昵称
/// - familyName: 姓
/// - middleName: 中间名
/// - givenName: 名
/// - avatarImage: 头像
/// - portraitImage: 人脸底图
/// - idType: ID类型
/// - idNumber: ID账号
/// - birthday: 生日,格式为yyyy-MM-dd
/// - gender: 性别
/// - company: 所在公司
/// - address: 所处地址
/// - block: 回调
+(void)userRegistrationWithPassCode:(NSString *)passCode
email:(NSString *)email
phoneNumber:(NSString *)phoneNumber
phoneCountryCode:(NSString *)phoneCountryCode
userName:(NSString *)userName
familyName:(NSString *)familyName
middleName:(NSString *)middleName
givenName:(NSString *)givenName
avatarImage:(NSString *)avatarImage
portraitImage:(NSString *)portraitImage
idType:(IdType)idType
idNumber:(NSString *)idNumber
birthday:(NSString *)birthday
gender:(GenderType)gender
company:(NSString *)company
address:(NSString *)address
completeBlock:(RequestCompleteServiceBlock)successBlock
errorBlock:(RequestErrorServiceBlock)errorBlock;
/// User deletion
/// 删除did账号的信息
/// - block: 回调
+(void)userDeletionWithCompleteBlock:(RequestCompleteServiceBlock)successBlock
errorBlock:(RequestErrorServiceBlock)errorBlock;
/// AccessToken refreshing
/// 使用RefreshToken在AccessToken快过期前刷新AccessToken生成新的AccessToken与RefreshToken
/// - Parameters:
/// - refreshToken: 刷新token
/// - block: 回调
+(void)refreshingAccessTokenWithRefreshToken:(NSString *)refreshToken
completeBlock:(RequestCompleteServiceBlock)successBlock
errorBlock:(RequestErrorServiceBlock)errorBlock;
/// Logout of AccessToken
/// 用户安全地退出登录。
/// - block: 回调
+(void)logoutWithCompleteBlock:(RequestCompleteServiceBlock)successBlock
errorBlock:(RequestErrorServiceBlock)errorBlock;
/// Organizational Information Inquiry
/// 获取当前组织基本信息。组织不存在返回为null
/// - block: 回调
+(void)getOrganizationalWithCompleteBlock:(RequestCompleteServiceBlock)successBlock
errorBlock:(RequestErrorServiceBlock)errorBlock;
/// kafd-access-control
/// 获取二维码
/// - block: 回调
+(void)qrcodesWithUserId:(NSString *)userId
completeBlock:(RequestCompleteServiceBlock)successBlock
errorBlock:(RequestErrorServiceBlock)errorBlock;
其中关于SMSChannel 、VerifyMethod 、IdType 、GenderType 的定义和说明,请查看
DIDSDKManagerDefine.h
SDK提供的文件
为了帮助您更好的使用DID SDK,我们提供的以下头文件和SDK需要的资源文件:
DID SDK Header | Bundle |
---|---|
SDK Manager |
cer |
SDK Network |
img |
SDK Cache |
language |
model |