/**设置循环滚动 */ #import "HomeBaseVC.h" #import "HmV0.h" #import "HmV1.h" #import "HmV2.h" #import "HmV3.h" #import "HmV4.h" #import "HmV5.h" #import "ScanVC.h" #import "Tools.h" #import "ThirdLoginBindYunGuanVC.h" #import "DistenceTooLongMapVC.h" #import "DES3Util.h" #import "TheoryTrainVC.h" #import //引入定位功能所有的头文件(新) #import "OliveappLivenessDetectionViewController.h" #import "OliveappCameraPreviewController.h" #import "OliveappDetectedFrame.h" #import "OliveappBase64Helper.h" @interface HomeBaseVC () { /** 分段选择器下方的滚动条。*/ UIView *btnBar; /** 保存scroll主页面。最后一次滚动的offset */ CGPoint lastOffset; /** 左上角的头像 */ UIImageView *headIv; NSString *headerImgPath; /** 这个值决定是否隐藏segment */ CGFloat _segmenHeight; /** 下面几个全局是为了隐藏选择科目条 */ UIView *barBg; //同步错题 UILabel *bgLabel; //集中式理论 BOOL isNeedTest; BOOL isCloseAudio; NSInteger maxTime; NSString *scanType; NSString *scanData; CLLocationCoordinate2D myLocation; } @property(nonatomic,strong)UIScrollView* scroll; /**分段选择器的按钮 */ @property(nonatomic,strong)NSMutableArray* btns; /**用于使scroll和按钮联动 */ @property(nonatomic,assign)NSInteger pageIndex; @property (strong, readwrite, nonatomic) NSString *faceIdStr; @end @implementation HomeBaseVC - (void)dealloc{ //移除指定的通知,不然会造成内存泄露 [[NSNotificationCenter defaultCenter] removeObserver:self name:@"Tiku_Change" object:nil]; } - (void)viewDidLoad { [super viewDidLoad]; [self myInit]; self.pageIndex = 1; headerImgPath = @"";//头像初始地址为空 // 移动question已做题到markQuestion // if (myDelegate.isSyn) { // myDelegate.isSyn = NO; // [DB_Que_Helper moveIsDoneToMarkQuestion];//移动已做题 // if (myDelegate.isLogin)//更新版本 先做一次同步 // { // [self syncQuestion]; // } // } } -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; //用户数据监控,实时更新头像。 [RACObserve(defUser, userDict) subscribeNext:^(NSDictionary *dic) { //更新头像 这样做的好处是 如果有更新就会立刻更新上,如果没有 就不用重新获取头像 节省流量 NSString *str = defUser.userDict[@"photo"]; if (str && ![str hasPrefix:@"http"]){ str = [imgPreFix stringByAppendingString:str]; } if (!str || str.length < 1) { str = @""; } if (![str isEqualToString:headerImgPath]) { [headIv sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"drawer_head.png"]]; headerImgPath = str; } }]; //判断是否理论计时 if (myDelegate.isLogin) { [self getStuSignFlag]; } } -(void)viewWillDisappear:(BOOL)animated{ if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { } else { [self setHidesBottomBarWhenPushed:NO]; } [super viewWillDisappear:animated]; } -(void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { } else { self.tabBarController.tabBar.hidden = NO; } } #pragma mark - -(void)myInit { //导航栏遮盖问题 self.navigationController.navigationBar.translucent = NO; self.navigationItem.title = @"优易学车"; self.view.backgroundColor = backGroundColor; [self.navigationItem.leftBarButtonItem setTintColor:defGreen]; //二维码扫描登陆网页 UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"erWeiMa.png"] originImageScaleToSize:CGSizeMake(22.5, 22.5)] style:UIBarButtonItemStyleDone target:self action:@selector(clickToScan)]; item.tintColor = defGreen; [self.navigationItem setRightBarButtonItem:item]; CGFloat sBoader = (kNavBarHeight - 35)/2.0; UIButton *sideBtn = [[UIButton alloc] initWithFrame:CGRectMake(sBoader, kStatusHeight + sBoader, kNavBarHeight - sBoader*2, kNavBarHeight - sBoader*2)]; [self.view addSubview:sideBtn]; UIImageView *iv = [[UIImageView alloc] initWithFrame:sideBtn.bounds]; [iv setBoardWid:1 Color:defGreen]; [iv setRound]; headIv = iv; [sideBtn addSubview:iv]; [sideBtn addTarget:self action:@selector(showLeftViewAction) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem* bbi0 = [[UIBarButtonItem alloc] initWithCustomView:sideBtn]; self.navigationItem.leftBarButtonItem = bbi0; //顶部滚动条 CGFloat barHeight = 2; CGFloat segmenHeight = kSegmenHeight-barHeight; NSArray *segItems = @[@"报名",@"科一",@"科二",@"科三",@"科四",@"下证"]; CGFloat segW = kSize.width/(segItems.count); _btns = [NSMutableArray array]; for (int i = 0; i 0) { UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"您本地有未上传学时,请确认上传!" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [self uploadMoreTrainRecordWithArray:trainArray]; }]; [alert addAction:saveAction]; [self presentViewController:alert animated:YES completion:nil]; } } } - (void)uploadMoreTrainRecordWithArray:(NSArray *)trainArray { if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSString* str = @""; for (TrainRecord *record in trainArray) { str = [str stringByAppendingString:[NSString stringWithFormat:@"%@,%@,%@,%@;",record.studentId,record.beginTime,record.endTime,record.trainTime]]; } TrainRecord *record = [trainArray firstObject]; NSMutableArray *arr=[NSMutableArray array]; [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"ios",@"trainType", nil]]; [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:[DES3Util encrypt:str ],@"trainRecord", nil]]; [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:record.subject,@"pxkm", nil]]; [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:defUser.userDict[@"outId"],@"stuOutid", nil]]; NSString* method = @"uploadMoreTrainRecord"; [MBProgressHUD showLoadToView:self.view]; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) { [MBProgressHUD hideHUDForView:self.view]; if (!dict) { ShowMsg(@"上传学时失败!"); return; } if ([dict[@"code"] isEqualToString:@"90"]) { UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:dict[@"msg"] preferredStyle:UIAlertControllerStyleAlert]; [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { [LoginViewController loginFromVC:self]; }]]; [self presentViewController:alertFind animated:true completion:nil]; return; } if ([dict[@"code"] isEqualToString:@"1"]) { ShowMsg(dict[@"body"]); return; } if ( [dict[@"code"] isEqualToString:@"0"]) { for (TrainRecord *record in trainArray) { [DB_Helper updateTrainState:record]; } UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"上传学时成功!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil]; [alert show]; } }]; } - (void)notificationAction:(NSNotification *)notification{ self.pageIndex = 1;//目的是回滚到科一的界面,只要切换了题库类型(上下/左右) if ([notification.userInfo[@"zhigezhengChanged"] isEqualToString:@"NO"]) { return; } CGFloat scroolY; if ([defUser.isZhiGeZheng isEqualToString:@"YES"]){ //在这里用——scroll将报名、科一、科二...那栏挡住 scroolY = 0; [_scroll setScrollEnabled:NO]; }else{ scroolY = kSegmenHeight; [_scroll setScrollEnabled:YES]; } _scroll.frame = CGRectMake(0, scroolY, kSize.width, kSize.height- kNavOffSet - scroolY - kTabBarHeight); } /**显示左边抽屉 */ -(void)showLeftViewAction { [self.sideVC showLeftViewController:true]; } -(void)clickToScan { if (!myDelegate.isLogin) { [LoadingView showMsg:@"请登录后操作"]; [LoginViewController loginFromVC:self]; return; } ScanVC *scan = [[ScanVC alloc] init]; scan.type = @"1"; [scan scanBlock:^(NSDictionary *dic) { //模拟 if ([dic[@"scanType"] isEqualToString:@"MNQTrain"]) { // 成功 //根据是否存在mnTrainType判断本地记录的学时编号等数据是否与服务器同步过(即登录完调的状态接口成功与否) if (myDelegate.mnTrainType) { myDelegate.mnTrainType = @"2";//已经登录未人脸验证 UINavigationController *nav = [LoginViewController getPeriodVCWithName:@"MNQtTrainVC"]; if (nav) { nav.modalPresentationStyle = UIModalPresentationFullScreen; [self presentViewController:nav animated:YES completion:nil]; } }else{ [MBProgressHUD showMessage:@"正在获取当前训练状态" toView:self.view]; //这个主要目的是为了更新本地学时编号等数据 [LoginViewController getCurrentStateWithCompleteBlock:^(NSDictionary *root) { [MBProgressHUD hideHUDForView:self.view animated:NO]; if (!root) { ShowMsg(@"请求失败"); return; } if ([root[@"code"] isEqualToString:@"0"]) { UINavigationController *nav = [LoginViewController getPeriodVCWithName:@"MNQtTrainVC"]; if (nav) { nav.modalPresentationStyle = UIModalPresentationFullScreen; [self presentViewController:nav animated:YES completion:nil]; } }else{ ShowMsg(root[@"msg"]); } }]; } return; } //理论扫码 NSInteger isNeed = 1; for (NSDictionary * dic in defUser.userDict[@"params"]) { if ([dic[@"KEY"] isEqualToString:@"SP_VERIFY_IMEI"]) { isNeed = [dic[@"VALUE"] integerValue]; } } NSString *IMEI = defUser.userDict[@"imei"]; if (IMEI.length > 0) { if (isNeed == 1) { if ([Tools getIDFAWithType:GetIDFAType_Default]) { if (![IMEI isEqualToString:[Tools getIDFAWithType:GetIDFAType_Default]]) { ShowMsg(@"请用本人手机进行理论计时"); return; } } }else{ [Tools saveNotBindImeiLogWithType:@"1" block:^(BOOL isSuccess) { }];//操作类型(1理论设备扫码,2远程计时,3模拟终端,4大车)
 } }else { UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:@"您暂未绑定学员账号,是否绑定?" preferredStyle:UIAlertControllerStyleAlert]; [alertFind addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]]; [alertFind addAction:[UIAlertAction actionWithTitle:@"去绑定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { ThirdLoginBindYunGuanVC *vc = [[ThirdLoginBindYunGuanVC alloc] init]; [self navPushHideTabbarToVC:vc]; }]]; [self presentViewController:alertFind animated:true completion:nil]; return; } isCloseAudio = YES; scanType = dic[@"scanType"]; scanData = dic[@"dataString"]; if ([dic[@"scanType"] intValue] == 2) { UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:@"是否结束理论学习?" preferredStyle:UIAlertControllerStyleAlert]; [alertFind addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]]; [alertFind addAction:[UIAlertAction actionWithTitle:@"结束计时" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { [self getMyLocation]; }]]; [self presentViewController:alertFind animated:true completion:nil]; }else { [self getMyLocation]; } }]; [self navPushHideTabbarToVC:scan]; [MBProgressHUD showMessage:@"正在获取当前位置..." toView:self.view]; [[MapManager sharedManager] updateLocationWithCompleteBlock:^(BOOL success, CLLocation *location) { [MBProgressHUD hideHUDForView:self.view animated:YES]; if (success) { self->myLocation = location.coordinate; // [self takePhoto]; [self getQgCode]; } }]; } #pragma mark - //0,1,2,3,4,5,6,7 -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ lastOffset = scrollView.contentOffset; NSInteger pInd = (int)(lastOffset.x / kSize.width); {//为了实现循环滚动 if (pInd < 1) { pInd = 6; } if (pInd > 6) { pInd = 1; } pInd--; } if (pInd != self.pageIndex) { self.pageIndex = pInd; } } /**分段按钮,和scroll联动*/ -(void)segSelected:(UIButton*)sender { if (sender.tag == self.pageIndex) { return; } self.pageIndex = sender.tag; } /**0-5 */ -(void)setPageIndex:(NSInteger)pageIndex{ //刷新错题提示 if (pageIndex==1) { myDelegate.subject = @"1"; HmV1 *vc = (HmV1 *)self.childViewControllers[2]; [vc getFaultCntNew]; }else if(pageIndex==4){ myDelegate.subject = @"4"; HmV4 *vc = (HmV4 *)self.childViewControllers[5]; [vc getFaultCntNew]; } [_btns[_pageIndex] setSelected:NO]; _pageIndex = pageIndex; [_btns[_pageIndex] setSelected:YES]; //为了实现循环滚动 [_scroll setContentOffset:CGPointMake(kSize.width*(pageIndex+1), _scroll.contentOffset.y) animated:NO]; //这里设置每次进入某一类型回滚到顶部 UIView *view = _scroll.subviews[pageIndex+1]; HmvBase *vc = (HmvBase *)view.nextResponder; [vc.zzScrollV setContentOffset:CGPointZero animated:NO]; CGSize size = btnBar.frame.size; [UIView animateWithDuration:.2 animations:^{ btnBar.frame = CGRectMake(size.width * _pageIndex, btnBar.frame.origin.y, size.width, size.height); }]; myDelegate.subject = [NSString stringWithFormat:@"%d",(int)pageIndex]; RQ_YDTQuestion_Module.subject = (pageIndex > 0 && pageIndex < 5)? pageIndex : 1; } #pragma mark 更新第一次进入同步数据 -(void)syncQuestion { if (![Util connectedToNetWork]) { return; } self.view.userInteractionEnabled = NO; bgLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, (kSize.height - 80)/2.0, kSize.width - 60, 70)]; bgLabel.backgroundColor = backGroundColor; [bgLabel setBoardWid:5 Color:contentTextColor]; [bgLabel setText:@"收藏、错题同步中,请稍后..." Font:24 TextColor:kTitleColor Alignment:NSTextAlignmentCenter]; [[UIApplication sharedApplication].keyWindow addSubview:bgLabel]; [self getMyQuestionType:@"" Subject:@""]; } -(void)getMyQuestionType:(NSString*)type Subject:(NSString*)subject; { NSMutableArray *arr = [NSMutableArray array]; [arr addPro:@"user" Value:defUser.userDict[@"id"]]; [arr addPro:@"outId" Value:defUser.userStuId]; [arr addPro:@"type" Value:type]; [arr addPro:@"subject" Value:subject]; [arr addPro:@"carType" Value:defUser.car_type]; [arr addPro:@"isPage" Value:@"0"]; [arr addPro:@"pageSize" Value:@"0"]; [arr addPro:@"currentPage" Value:@"0"]; NSString *method = @"getMyQuestionFavs"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) { //NSLog(@"同步错题收藏---->%@--->%@",arr,root); if (!root || [root[@"code"] isEqualToString:@"1"]) { [self removebgLabel]; ShowMsg(@"题库错题、收藏、排除同步失败,请在侧栏手动同步"); return; } NSArray* body = [root objectForKey:@"body"]; if (body.count > 0) { if ([defUser.car_type isEqualToString:@"2"]) { if ([DB_Que_Helper deleteGZPZ_EXAM_CYRYAllMarkQuestion]) { [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithArray:body]; } } else { if ([DB_Que_Helper deleteAllMarkQuestion]) { [DB_Que_Helper setMarkQuestionWithArray:body]; } } } [self removebgLabel]; ShowMsg(@"题库错题、收藏、排除已同步完毕"); }]; } -(void)removebgLabel { if (bgLabel) { [bgLabel removeFromSuperview]; bgLabel = nil; } self.view.userInteractionEnabled = YES; } //获取当前学员计时状态 - (void)getStuSignFlag { if (![Util connectedToNetWork]) { return; } NSString *stuId = defUser.userDict[@"outId"]; if (!stuId || stuId.length == 0) { return; } NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"stuId" Value:stuId]; [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]]; NSString* method = @"getStuSignFlag"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) { if (!root || [root[@"code"] integerValue] == 1) { return; } //这里接收服务器返回状态 当前训练培训训练状态 0 未签到 4集中理论签到中 // if ([[root[@"body"] objectForKey:@"status"] integerValue] == 0) { // //还没开始集中式理论 // // } // if ([[root[@"body"] objectForKey:@"status"] integerValue] == 4) { // //集中式理论学习中 // } if ([[root[@"body"] objectForKey:@"theoryVerify"] integerValue] == 1) { //开启过程验证 isNeedTest = YES; }else { //关闭过程验证 isNeedTest = NO; } NSInteger newTime = [[root[@"body"] objectForKey:@"timre"] integerValue]; maxTime = [[root[@"body"] objectForKey:@"theoryTime"] integerValue]; if ([[root[@"body"] objectForKey:@"status"] integerValue] == 4) {//已经签到 集中式计时中 myDelegate.trainStateLabel.text = @"理论学习中..."; if (isNeedTest) { if (maxTime > newTime) { [self setNotificationWithFireTime:maxTime - newTime withType:LocalNotificationTypeTheory]; }else { myDelegate.trainStateLabel.text = @"请扫描过程验证二维码"; if (isCloseAudio) { isCloseAudio = NO; }else { [Tools playAudioWithString:@"请扫描过程验证二维码"]; } } } }else { myDelegate.trainStateLabel.text = @""; } }]; } //语音播报或者推送 - (void)setNotificationWithFireTime:(NSInteger)fireTime withType:(LocalNotificationType)localNotificationType{ switch (localNotificationType) { /// 课堂 case LocalNotificationTypeTheory: { NSString *identifierStr = @"Theory"; /// 间隔时间大于5分钟(300秒) if (fireTime >= 300) { NSInteger timeInterval = fireTime - 300; // if (DEBUG) { // timeInterval = 120; // } [RQ_LocalNoti_Manager removeNotificationWithIdentifierID:identifierStr]; [RQ_LocalNoti_Manager addLocalNotificationWithTitle:@"优易学车提醒您" subTitle:@"5分钟后将超过验证时间,请提前扫码验证" body:[RQ_SHARE_FUNCTION getCurrentTimeStringWithTimeStamp:timeInterval] timeInterval:timeInterval identifier:identifierStr userInfo:@{@"identifier" : identifierStr , @"message" : @"即将超过验证时间,请提前扫码验证"} repeats:0]; } else { [RQ_LocalNoti_Manager removeNotificationWithIdentifierID:identifierStr]; [RQ_LocalNoti_Manager addLocalNotificationWithTitle:@"优易学车提醒您" subTitle:@"即将超过验证时间,请提前扫码验证" body:[RQ_SHARE_FUNCTION getCurrentTimeStringWithTimeStamp:0] timeInterval:0 identifier:identifierStr userInfo:@{@"identifier" : identifierStr , @"message" : @"即将超过验证时间,请提前扫码验证"} repeats:0]; } break; } /// 模拟 case LocalNotificationTypSsimulation: { //移除旧的通知 if ([[[UIApplication sharedApplication] scheduledLocalNotifications] count] > 0) { [[UIApplication sharedApplication] cancelAllLocalNotifications]; } //定义本地通知对象 UILocalNotification *notification = [[UILocalNotification alloc]init]; //设置调用时间 notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:fireTime]; //设置通知属性 notification.alertBody = @"优易学车提醒您"; //通知主体 notification.applicationIconBadgeNumber = 1;//应用程序图标右上角显示的消息数 notification.alertAction = @"打开应用"; //待机界面的滑动动作提示 notification.soundName = @"TrainTest.mp3";//收到通知时播放的声音,默认消息声音 // 通知参数 NSDictionary *userDict = [NSDictionary dictionaryWithObjectsAndKeys:@"nothing",@"ShiCaoPeriodVC_reTakePhoto", nil]; notification.userInfo = userDict; //调用通知 [[UIApplication sharedApplication] scheduleLocalNotification:notification]; break; } default: break; } } - (void)cancelLocalNotificationWithType:(LocalNotificationType)localNotificationType { switch (localNotificationType) { /// 课堂 case LocalNotificationTypeTheory: { NSString *identifierStr = @"Theory"; [RQ_LocalNoti_Manager removeNotificationWithIdentifierID:identifierStr]; break; } /// 模拟 case LocalNotificationTypSsimulation: { //移除旧的通知 if ([[[UIApplication sharedApplication] scheduledLocalNotifications] count] > 0) { [[UIApplication sharedApplication] cancelAllLocalNotifications]; } break; } default: break; } } - (void)getMyLocation { //定位功能 [MBProgressHUD showMessage:@"正在获取当前位置..." toView:self.view]; [[MapManager sharedManager] updateLocationWithCompleteBlock:^(BOOL success, CLLocation *location) { [MBProgressHUD hideHUDForView:self.view animated:YES]; if (success) { self->myLocation = location.coordinate; [self studentQrcode]; } }]; } /** 扫描二维码调取接口 */ - (void)studentQrcode { if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } if (myLocation.longitude == 0.0) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"位置获取失败,请重新扫描二维码!" message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; [alert show]; return; } NSMutableArray *arr = [NSMutableArray array]; [arr addPro:@"studentOutid" Value:defUser.userDict[@"outId"]]; [arr addPro:@"qrcode" Value:scanData]; [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]]; [arr addPro:@"lng" Value:[NSString stringWithFormat:@"%f",myLocation.longitude]]; [arr addPro:@"lat" Value:[NSString stringWithFormat:@"%f",myLocation.latitude]]; // [arr addPro:@"lng" Value:@"123.907972"]; // [arr addPro:@"lat" Value:@"41.887931"]; [arr addPro:@"type" Value:scanType]; [arr addPro:@"telType" Value:@"ios"]; if (_faceIdStr && ![_faceIdStr isEqualToString:@""]) { [arr addPro:@"faceId" Value:_faceIdStr]; _faceIdStr = @""; } NSString *method = @"studentQrcode"; NSString *str = [scanType isEqualToString: @"1"] ? @"签到中...":@"签退中..."; if ([scanType isEqualToString: @"1"] ) { str = @"签到中..."; }else if ([scanType isEqualToString: @"2"]) { str = @"签退中..."; }else if ([scanType isEqualToString: @"3"]) { str = @"验证中..."; } [MBProgressHUD showMessage:str toView:self.view]; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) { [MBProgressHUD hideHUDForView:self.view]; if (!root) { ShowMsg(@"操作失败,请重试!"); [Tools playAudioWithString:@"操作失败,请重试!"]; return; } if ([root[@"code"] integerValue] == 0) {//代表操作成功 if ([scanType isEqualToString:@"1"] || [scanType isEqualToString:@"3"]) { myDelegate.trainStateLabel.text = @"理论学习中..."; } if ([scanType isEqualToString:@"2"]) { myDelegate.trainStateLabel.text = @""; } // if (DEBUG) { // isNeedTest = YES; // } if (isNeedTest) { switch ([scanType integerValue]) { //1、签到 2、签退 3、过程验证 case 1://签到成功 if (maxTime > 0) { [self setNotificationWithFireTime:maxTime withType:LocalNotificationTypeTheory]; } break; case 2://签退 [self cancelLocalNotificationWithType:LocalNotificationTypeTheory]; break; case 3://验证成功 if (maxTime > 0) { [self setNotificationWithFireTime:maxTime withType:LocalNotificationTypeTheory]; } break; default: break; } } } if ([root[@"code"] integerValue] == 2) {//距离理论教室位置较远 NSString *str = root[@"msg"]; if (str.length < 1) { return; } NSArray *mapArray = [str componentsSeparatedByString:@";"]; UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:[mapArray lastObject] preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]]; [alert addAction:[UIAlertAction actionWithTitle:@"查看位置详情" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { //进入地图页面 传入两个点 一个距离 lng lat len if (mapArray.count > 3) { // lng = 123.467129, // lat = 41.813997 //122.769684;41.515881;66822;您当前距离理论教室位置66822米,请到理论教室扫码! DistenceTooLongMapVC *mapVC = [[DistenceTooLongMapVC alloc] init]; mapVC.lat1 = myLocation.latitude; mapVC.lng1 = myLocation.longitude; mapVC.lat2 = [mapArray[1] floatValue]; mapVC.lng2 = [mapArray[0] floatValue]; mapVC.distence = mapArray[2]; mapVC.skipMspBlock = ^{ myLocation.longitude = 0.0; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"位置已重置,请重新扫描二维码!" message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; [alert show]; }; [self navPushHideTabbarToVC:mapVC]; } }]]; [self presentViewController:alert animated:true completion:nil]; return; } // 需要进行人脸比对 if ([root[@"code"] integerValue] == 99) { [self takePhoto]; return; } [Tools playAudioWithString:root[@"msg"]]; ShowMsg(root[@"msg"]); }]; } // 人脸比对 - (void)takePhoto { UIStoryboard * board = [UIStoryboard storyboardWithName:@"LivenessDetection" bundle:nil]; OliveappLivenessDetectionViewController * livenessDetectionViewController; livenessDetectionViewController = (OliveappLivenessDetectionViewController *)[ board instantiateViewControllerWithIdentifier:@"LivenessDetectionStoryboard"]; livenessDetectionViewController.modalPresentationStyle = 0; livenessDetectionViewController.faceDelegate = self; OliveappSessionManagerConfig* config = [OliveappSessionManagerConfig new]; // config.timeoutMs = 100000; [config usePredefinedConfig: 4]; // 这里配置检测步骤 livenessDetectionViewController.cusConfig = config; NSError *error; BOOL isSuccess = [livenessDetectionViewController setConfigLivenessDetection:self withError: &error]; if (isSuccess){ [self presentViewController:livenessDetectionViewController animated:YES completion:nil]; } } - (void)onLivenessSuccess:(OliveappDetectedFrame *)detectedFrame{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self dismissViewControllerAnimated:YES completion:nil]; }); } - (void)onLivenessFail:(int)sessionState withDetectedFrame:(OliveappDetectedFrame *)detectedFrame{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self dismissViewControllerAnimated:YES completion:nil]; UIAlertController *actionsheet = [UIAlertController alertControllerWithTitle:@"提示" message:@"获取人脸失败,是否重新进行人脸比对" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"是" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [self takePhoto]; }]; UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"否" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [actionsheet addAction:action1]; [actionsheet addAction:action2]; [self presentViewController:actionsheet animated:YES completion:nil]; }); } - (void)onLivenessCancel{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self dismissViewControllerAnimated:YES completion:nil]; }); } - (void)sendFaceImage:(UIImage *)faceImage { UIImage *normalImage = [UIImage fixOrientation:faceImage]; NSData *imgData = UIImageJPEGRepresentation(normalImage, .2f); NSString *backString = [NSString stringWithFormat:@"%@",[OliveappBase64Helper encode:imgData]]; [self face2faceTheoryWithPhotoStr:backString ResultBlock:^(NSString *faceId) { if (![faceId isEqualToString:@""]) { _faceIdStr = faceId; [self studentQrcode]; } }]; } - (void)sendFaceImageError { } - (void)face2faceTheoryWithPhotoStr:(NSString *)photoStr ResultBlock:(void (^)(NSString *faceId))resultBlock { if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } if (myLocation.longitude == 0.0) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"位置获取失败,请重新扫描二维码!" message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; [alert show]; return; } NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"stunum" Value:defUser.userDict[@"stuNum"]]; [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]]; [arr addPro:@"outId" Value:defUser.userDict[@"outId"]]; [arr addPro:@"lng" Value:[NSString stringWithFormat:@"%f",myLocation.longitude]]; [arr addPro:@"lat" Value:[NSString stringWithFormat:@"%f",myLocation.latitude]]; [arr addPro:@"photo" Value:photoStr]; NSString *method = @"face2faceTheory"; [MBProgressHUD showHUDAddedTo:self.view animated:YES]; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) { [MBProgressHUD hideHUDForView:self.view]; if (!root) { ShowMsg(@"操作失败,请重试!"); [Tools playAudioWithString:@"操作失败,请重试!"]; return; } if ([root[@"code"] integerValue] == 0) {//代表操作成功 if (resultBlock && root[@"data"][@"faceId"]) { resultBlock(root[@"data"][@"faceId"]); } } [Tools playAudioWithString:root[@"msg"]]; ShowMsg(root[@"msg"]); }]; } - (void)getQgCode { if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"dqbh" Value:@"2101"]; [arr addPro:@"sim" Value:@"12101000042"]; [arr addPro:@"roomId" Value:@"343"]; [arr addPro:@"coachNum" Value:@"3623240296803372"]; [arr addPro:@"type" Value:@"3"]; NSString *method = @"getQgCode"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) { }]; } @end