DFRecognizeController类介绍
初始化
/// 上传识别页面初始化
/// @param image 捕捉到的卡证图片
/// @param cardSide 卡证类型
/// @param cardType 检测类型
/// @param isCopy 是否是复印件
/// @param successBlock 成功回调
/// @param failedBlock 失败回调
- (instancetype)initWithImage:(UIImage *)image
cardSide:(DFCardDetectedSide)cardSide
cardType:(DFCardDetectedType)cardType
isCopy:(BOOL)isCopy
successBlock:(DFCardDetectedSuccessfullyBlock)successBlock
failedBlock:(DFCardDetectedFailedBlock)failedBlock;
上传识别
当调起DFCaptureController时autoRecognize如果为YES则需要设置
NSString *DFApiID = @"账号";
NSString *DFApiSecret = @"密码";
- (void)uploadForRecognize
{
[self animationing];
NSString *baseUrl = @"https://cloudapi.deepfinch.com";
AFHTTPRequestOperationManager *requestOperationManager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:baseUrl]];
requestOperationManager.requestSerializer = [AFHTTPRequestSerializer serializer];
requestOperationManager.responseSerializer = [AFJSONResponseSerializer serializer];
__weak typeof(self) weakSelf = self;
void (^successBlock)(AFHTTPRequestOperation *operation, id responseObject) = ^(AFHTTPRequestOperation *operation, id responseObject) {
[weakSelf stopAnimating];
NSDictionary *dic = responseObject;
[weakSelf handleDic:[dic objectForKey:@"result"] image:weakSelf.image];
};
void (^failBlock)(AFHTTPRequestOperation *operation, NSError *error) = ^(AFHTTPRequestOperation *operation, NSError *error){
NSDictionary *dic = [operation.responseObject isKindOfClass:[NSDictionary class]] ? operation.responseObject : @{};
[weakSelf stopAnimating];
NSString *status = [dic objectForKey:@"status"];
NSString *errMessage = [self.errorMessageDict objectForKey:status] ?: @"请检测网络是否正常";
if (weakSelf.faileddBlock) {
weakSelf.faileddBlock(errMessage);
}
};
NSMutableDictionary *params = [NSMutableDictionary dictionary];
NSString *url;
switch (self.cardSide) {
case DFCardDetectedSideIDCardFront:
case DFCardDetectedSideIDCardBack:
url = DFIDCardRecognionAddress;
break;
case DFCardDetectedSideBankCardFront:
url = DFBankCardRecognionAddress;
break;
case DFCardDetectedSideVehicleLicenseFrontFront:
case DFCardDetectedSideVehicleLicenseFrontBack:
case DFCardDetectedSideVehicleLicenseBackFront:
case DFCardDetectedSideVehicleLicenseBackBack:
url = DFVehicleRecongnionAddress;
break;
case DFCardDetectedSideDrivingLicenseFrontFront:
case DFCardDetectedSideDrivingBackFront:
url = DFDriveRecognionAddress;
break;
default:
break;
}
#error Please set api_id and api_secret if you set autoRecognize to YES or set autoRecognize to NO and delete this line.
NSString *DFApiID = @"账号";
NSString *DFApiSecret = @"密码";
[requestOperationManager.requestSerializer setValue:DFApiID forHTTPHeaderField:@"X-DF-API-ID"];
[requestOperationManager.requestSerializer setValue:DFApiSecret forHTTPHeaderField:@"X-DF-API-SECRET"];
[requestOperationManager POST:url parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
__strong typeof(weakSelf) strongSelf = weakSelf;
NSData *data = UIImageJPEGRepresentation(strongSelf.image, 0.8);
[formData appendPartWithFileData:data name:@"file" fileName:@"image" mimeType:@"image/jpeg"];
} success:successBlock failure:failBlock];
}