真人认证SDK快速指南-iOS
1. 接入指南
1.1. Cocoapods接入
- 在工程Podfile文件中添加如下代码:
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/cosmos33/MMSpecs.git'
pod 'MMFaceCertification'
- 在终端窗口项目根目录中运行以下命令:
$ pod install
- 向Info.plist文件中添加相机权限
<plist version="1.0">
<dict>
...
<key>NSCameraUsageDescription</key>
<string>真人认证需要使用相机</string>
...
</dict>
</plist>
1.2. 设置AppId及初始化环境
请务必在使用SDK前加入如下代码,这会将AppId注册进SDK,并完成SDK的环境初始化
#import <MMFaceCertification/MNFCService.h>
[MNFCService configAppId:<YourAPPId>];
if (![MNFCService isPrepared]) {
[MNFCService prepareEnvironment:^(BOOL prepared) {
}];
}
2. 使用认证功能
认证功能可以对用户进行真人认证,认证成功后会获得personId
2.1. 设置控制器配置MNFCDetectionConfig
参数 | 说明 |
---|---|
detectionType | MNFCDetectionType: 检测模式,分为交互式和静默式,默认为交互式 |
motionDetectionCount | NSUInteger: 指定交互式扫脸模式下交互动作的数量,默认为4 |
resultCallBack | Block: 处理认证结果的回调 |
2.2. 开启认证界面控制器
[MNFCService startCertificationWithConfig:config];
3. 图片匹配
图片匹配功能可以对图片中的人物进行识别,获得与指定personId的相似度分值
// 图片识别接口
[MNFCService comparePerson:personId image:image completionHandler:^(MNCompareResult * _Nullable compareResult, MNFCDetectionError errorCode) {
//获得比对结果
}];
// 图片URL识别接口
[MNFCService comparePerson:personId imageURL:imageURL completionHandler:^(MNCompareResult * _Nullable compareResult, MNFCDetectionError errorCode) {
//获得比对结果
}];
4. 图片搜索
图片搜索功能可以对图片中的人物进行识别,搜索获得指定集合中满足指定相似度的前N个personId
// 图片搜索
[MNFCService searchPersonsInSet:setId // 集合Id
threshold:threshold // 相似度阈值
count:count // 查询结果最大数量, 即topN
image:image // 图片
completionHandler:^(MNSearchResult * _Nullable searchResult, MNFCDetectionError errorCode) {
}];
// 图片URL搜索
[MNFCService searchPersonsInSet:setId // 集合Id
threshold:threshold // 相似度阈值
count:count // 查询结果最大数量, 即topN
imageURL:imageURL // 图片URL
completionHandler:^(MNSearchResult * _Nullable searchResult, MNFCDetectionError errorCode) {
}];