本地雙錄 SDK
更新時間:
通過閱讀本文,您可以快速了解本地雙錄 MPIDRSProcess iOS SDK 的相關功能及調(diào)用方法。
iOS 接入
創(chuàng)建項目工程
使用 xcode 創(chuàng)建一個新的項目。
環(huán)境配置
SDK 環(huán)境依賴
MPIDRSProcess SDK依賴 APMUtils、Texel、MPIDRSSDK(動態(tài)庫)。
參數(shù)配置
添加 MPIDRSSDK.framework 動態(tài)庫,同時添加其他必要的庫文件,如下圖所示。
添加 MPIDRSProcess.bundle 資源。
將 Other Linker Flags 設置為 -ObjC。
支持 HTTP 請求,即在
App Transport Security Settings
字段下加入Allow Arbitrary Loads
,并配置為 YES,如下圖所示。允許使用相機、麥克風權限。
MPIDRSProcess 功能
初始化 MPIDRSProcess SDK
FlowCreateConfig * config = [[FlowCreateConfig alloc] init];
config.ak = Ak;
config.sk = Sk;
config.appId = AppId;
config.userId = [DemoSetting sharedInstance].userId;
config.packageName = PackageName;//包名、暫時手動傳輸
config.processId = ProcessId;//控制臺生成的流程Json的Id
config.ocrroi = @[@0.2,@0.2,@0.6,@0.6];//身份證ROI設置
config.ocrRotate = 0;//身份證檢測角度
config.isOcrFront = true;//檢測身份證哪一面
config.presetSize = FlowRecorderPresetSize360P;
config.isHorizontal = true;//是否橫屏錄制
self.processSdk = [[IDRSFlow alloc] initIDRSWithDelegate:self Config:config success:^(NSString *string, JsonBlock jsonBlock) {
//接收流程Json
//string:流程Json ----- 需要自行添加人臉圖片及文本中姓名的替換
//事例見:Demo
NSLog(@"%@",string);
//、、、
//修改流程Json---添加檢測人的照片base64---修改播報字段最終的姓名內(nèi)容
NSString * jsonxx = newString;
//返回給SDK
jsonBlock(jsonxx);//返回給SDK
}];
開啟攝像頭
//Orientation確定了視頻流角度、而檢測需要這個角度、如果此處角度為您頁面角度、則檢測角度為0即可
[self.processSdk startCameraWithOrientation:AVCaptureVideoOrientationLandscapeRight back:^(UIView *cameraView) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.view addSubview:cameraView];
[self.view sendSubviewToBack:cameraView];
cameraView.frame = self.view.frame;
});
}];
切換攝像頭
[self.processSdk switchCamera:^(BOOL result) {
NSLog(@"Demo :: 切換攝像頭 %@",result?@"成功":@"失敗");
}];
開始流程
[self.processSdk startFlow];
//流程說明:如果有語音,語音播放完畢后、自動開啟第一個檢測項、其他檢測項需要手動調(diào)用下一項
// 如果沒有語音,則自動開始第一個檢測項、之后操作與上述一致
開始下一個檢測項
[self.processSdk startNextDetection];
開始上一章
[self.processSdk reLastPage];
重新檢測當前項
[self.processSdk repeatCurrentDetection];
重新播放當前章節(jié)
[self.processSdk replayCurChapter];
暫停/恢復播放
[self.processSdk flowPause];//播放暫停
[self.processSdk flowResume];//恢復播放
添加當前自定義章節(jié)的結果
[self.processSdk AddCurChapterCustomResult:@"自定義結果"];
清空默認路徑下的視頻及 meta/result 文件
[self.processSdk wipeCache];
銷毀
請及時使用銷毀、否則可能影響下次初始化。
[self.processSdk destroy];
MPIDRSProcess 回調(diào)
相機流的回調(diào)
- (void)flowCameraView:(UIView *)cameraView didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
{
//相機流回調(diào)
}
人臉位置回調(diào)
//人臉位置
-(void)onFaceDetectUi:(NSArray<faceUIAndName *> *)resules
{
self.faceView.detectResult = resules;
//可根據(jù)resules判斷人是否齊全等檢驗操作
}
手位置回調(diào)
- (void)onHandDetectUi:(NSArray<HandDetectionOutput *> *)results
{
self.handView.detectResult = results;
}
音頻文件下載狀態(tài)回調(diào)
- (void)downloadAudio:(float)per percent:(NSString *)percent isAll:(BOOL)isAll error:(NSError *)error{
if (error) {
return;
}
dispatch_async(dispatch_get_main_queue(), ^{
self.operateResult.text = [NSString stringWithFormat:@"當前文件進度:%.2f %% \n 總文件下載進度:%@\n是否全部下載完成:%@",per,percent,isAll?@"下載完成":@"未完成"];
});
}
章節(jié)開始回調(diào)
//章節(jié)開始
- (void)onPhaseStarted:(CheckResult *)phase
{
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"------xxxxx----:%u",phase.Type);
switch (phase.Type) {
case id_card_recognize:
NSLog(@"------xxxxx----:身份證框出現(xiàn)");
self.imageView.hidden = false;
break;
case sign_classify_recognize:
NSLog(@"------xxxxx----:簽名框出現(xiàn)");
self->_greenpick.hidden = false;
break;
default:
break;
}
self.operateResult.text = [NSString stringWithFormat:@"%@\n%@\n%@",phase.phaseId,phase.detectionId,phase.content];
if (![phase.phaseId isEqual:self->_curPhaseId]) {
self->_curPhaseId = phase.phaseId;
[[scollLabelView shareManager] setTextViewWithString:phase.content];
[[scollLabelView shareManager] setTextViewLocation:0];
}
});
NSLog(@"%@",phase.content);
}
超時回調(diào)
//超時
- (void)onDetectionFail:(id)body
{
NSLog(@"DetectionFail--%@",body);
dispatch_async(dispatch_get_main_queue(), ^{
self.operateResult.text = body;
//可以在超時之后再顯示下一步(跳過)按鈕
});
}
檢測成功回調(diào)
//檢測成功
- (void)onDetectionSuccess:(SuccessModel*)body
{
dispatch_async(dispatch_get_main_queue(), ^{
NSString *zhangjie = body.checkResult.phaseId;
NSString *jiancexiang = body.checkResult.detectionId;//=檢測類型
NSString *neirong = @"";
switch (body.checkResult.Type) {
case face_track:
break;
case face_recognize:
break;
case liveness_track:
break;
case speech_word_detect:
neirong = body.speech_word_Result;
self.operateResult.text = neirong;
break;
case id_card_recognize:{
if (body.ocrOutput.num.length > 0) {
neirong = body.ocrOutput.num;
}else {
neirong = body.ocrOutput.date;
}
self.imageView.hidden = true;
self.operateResult.text = neirong;
}
break;
case sign_action_recognize:
neirong = body.sign_action_Result;
self.operateResult.text = neirong;
break;
case static_hand_recognize:
neirong = [NSString stringWithFormat:@"%@",body.static_hand_Result];
self.operateResult.text = neirong;
break;
case sign_classify_recognize:
neirong = body.sign_classify_Result==0?@"手寫":@"非手寫";
self.operateResult.text = neirong;
self->_greenpick.hidden = true;
break;
case other:
neirong = body.other;
self.operateResult.text = neirong;
break;
default:
break;
}
NSLog(@"onDetectionSuccess 章節(jié):%@ 檢測項:%@ 內(nèi)容:%@",zhangjie,jiancexiang,neirong);
});
}
章節(jié)結束回調(diào)
//章節(jié)完成
- (void)onPhaseComleted:(CheckResult *)phase
{
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"------xxxxx----:%u",phase.Type);
switch (phase.Type) {
case id_card_recognize:{
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"------xxxxx----:身份證框隱藏");
self.imageView.hidden = true;
});
}
break;
case sign_classify_recognize:{
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"------xxxxx----:簽名框隱藏");
self->_greenpick.hidden = true;
});
}
break;
default:
break;
}
});
NSLog(@"%@",phase.content);
}
TTS 合成數(shù)據(jù)回調(diào)
//tts合成數(shù)據(jù)返回
- (void)onTTSCallBackwithText:(char *)text word_idx:(int)word_idx buffer:(char *)buffer len:(int)len taskid:(char *)taskid
{
NSLog(@"TTSCallBack:%s----%d",text,word_idx);
[[scollLabelView shareManager] setTextViewLocation:word_idx];
}
文件上傳狀態(tài)回調(diào)
- (void)ossUploadWithStarted:(BOOL)isRun msg:(NSString *)msg
{
dispatch_async(dispatch_get_main_queue(), ^{
self.maskView.label.text = msg;
self.maskView.label.numberOfLines = 0;
[self.maskView.label sizeToFit];
if (isRun) {
self->_maskView.hidden = false;
//蒙層旋轉等待
//可標注當前上傳的文件信息 msg
[self.maskView loadingViewShow];
}else {
//蒙層按鈕狀態(tài)
[self.maskView loadingViewHidden];
}
});
}
全部流程完成回調(diào)
//全部流程完成
- (void)onFlowCompleted
{
self.operateResult.text = @"章節(jié),全部完成";
NSLog(@"章節(jié),全部完成");
//如需錄制下一單、需要退出后重新進入
}
報錯信息回調(diào)
//報錯信息
- (void)onError:(NSDictionary *)errorDic withParam:(IDRSUploadManagerParam *)param
{
// NSDictionary *errorDic = @{
// @"domain":domain,
// @"code":@(code),
// @"position":position,
// @"msg":msg
// };
if (param) {
//上傳失敗后、返回來的可用于重試/以后上傳的參數(shù)信息
__unused IDRSUploadManagerParam * sasda = param;
}
NSString *domain = errorDic[@"domain"];
int code = [errorDic[@"code"] intValue];
NSString *position = errorDic[@"position"];
NSString *errorString = [NSString stringWithFormat:@"%@\ncode: -%d\n位置:%@",domain,code,position];
[[DemoToast shareInstance] makeToast:errorString duration:3];
}
資源下載狀態(tài)回調(diào)
//資源下載
-(void)onRemoteDownLoadModuleType:(IDRSDownLoadModuleType)type progress:(float)per allPro:(NSString *)percent error:(NSError *)error
{
NSLog(@"進度狀態(tài):%@ - 下載進度:%.2f - 文件總進度:%@",type == IDRSDownLoadModuleTypeDone ? @"下載完成":@"下載中", per,percent);
if (error) {
NSLog(@"進度狀態(tài):下載異常 :%@",error);
_circleView.msgLab.text = @"下載異常";
}
if (type == IDRSDownLoadModuleTypeDone) {
_circleView.msgLab.text = @"下載完成";
}
[_circleView setPercent:per andText:percent];
}
文檔內(nèi)容是否對您有幫助?