// // RQHomePageViewController.m // RQCommon // // Created by 张嵘 on 2018/11/21. // Copyright © 2018 张嵘. All rights reserved. // #import "RQHomePageViewController.h" #import "HmV0.h" #import "HmV1.h" #import "HmV2.h" #import "HmV3.h" #import "HmV4.h" #import "HmV5.h" #import "MapManager.h" #import "ScanVC.h" #import "Tools.h" #import "ThirdLoginBindYunGuanVC.h" #import "DistenceTooLongMapVC.h" #import "DES3Util.h" #import "TheoryTrainVC.h" #import "DistenceTooLongMapVC.h" #import //引入定位功能所有的头文件(新) #import "OliveappLivenessDetectionViewController.h" #import "OliveappCameraPreviewController.h" #import "OliveappDetectedFrame.h" #import "OliveappBase64Helper.h" @interface RQHomePageViewController () /// viewModel @property (nonatomic, readonly, strong) RQHomePageViewModel *viewModel; @property (nonatomic, readwrite, strong) JXPagerView *pagerView; @property (nonatomic, readwrite, strong) JXCategoryTitleView *categoryView; @property (nonatomic, readwrite, copy) NSArray *titles; @property (nonatomic, readwrite, strong) LeftViewController *leftVC; //集中式理论 @property (nonatomic, readwrite, assign) BOOL isNeedTest; @property (nonatomic, readwrite, assign) BOOL isCloseAudio; @property (nonatomic, readwrite, assign) NSInteger maxTime; @property (nonatomic, readwrite, copy) NSString *scanType; @property (nonatomic, readwrite, copy) NSString *scanData; @property (nonatomic, readwrite, assign) CLLocationCoordinate2D myLocation; @property (strong, readwrite, nonatomic) NSString *faceIdStr; @end @implementation RQHomePageViewController @dynamic viewModel; #pragma mark - SystemMethod - (void)viewDidLoad { [super viewDidLoad]; if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { if (!RQObjectIsNil(defUser.userDict)) { [defUser removeUserInfo]; } } else { if (myDelegate.isLogin) { //更新登录信息 如果是登录状态的时候 [LoginViewController reLoginFromViewController:self finishBlock:^{ [LoginViewController getCurrentStateWithCompleteBlock:nil]; }]; } } /// 初始化 [self rq_setup]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { } else { //判断是否理论计时 if (myDelegate.isLogin) { [self getStuSignFlag]; } } } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { } else { [self setHidesBottomBarWhenPushed:NO]; } } - (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; self.pagerView.frame = CGRectMake(0, RQ_APPLICATION_TOP_BAR_HEIGHT, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT - RQ_APPLICATION_TOP_BAR_HEIGHT - RQ_APPLICATION_TAB_BAR_HEIGHT - (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? 0 : RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT)); } - (void)dealloc{ //移除指定的通知,不然会造成内存泄露 [[NSNotificationCenter defaultCenter] removeObserver:self name:@"Tiku_Change" object:nil]; } #pragma mark - PrivateMethods /// 初始化 - (void)rq_setup { /// set up ... [self.view addSubview:self.pagerView]; if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { //头像 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.image = [UIImage imageNamed:@"drawer_head"]; iv.contentMode = UIViewContentModeScaleAspectFill; [iv borderColor:defGreen width:1 cornorRadios:6]; [iv setRound]; [sideBtn addSubview:iv]; [sideBtn addTarget:self action:@selector(showLeftViewAction) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem* bbi0 = [[UIBarButtonItem alloc] initWithCustomView:sideBtn]; self.navigationItem.leftBarButtonItem = bbi0; } else { [[RACObserve(defUser, userDict) distinctUntilChanged] subscribeNext:^(NSDictionary *dic) { //头像 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 sd_setImageWithURL:[NSURL URLWithString:dic[@"photo"]] placeholderImage:[UIImage imageNamed:@"drawer_head"]]; iv.contentMode = UIViewContentModeScaleAspectFill; [iv borderColor:defGreen width:1 cornorRadios:6]; [iv setRound]; [sideBtn addSubview:iv]; [sideBtn addTarget:self action:@selector(showLeftViewAction) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem* bbi0 = [[UIBarButtonItem alloc] initWithCustomView:sideBtn]; self.navigationItem.leftBarButtonItem = bbi0; }]; //检测本地是否有学时未上传 如果有不能进行任何操作 if (myDelegate.isLogin && defUser.isycbd != 1) { NSString *pxkm = defUser.userDict[@"pxjd"]; if (pxkm.length < 1) { pxkm = @"1"; } NSArray* trainArray = [DB_Helper quearyTrain:defUser.userStuId Subject:pxkm]; if (trainArray.count > 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]; } } //二维码扫描登陆网页 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]; } // if (myDelegate.isSyn) { // myDelegate.isSyn = NO; // // if ([myDelegate.markQuestionTableData isKindOfClass:[NSMutableArray class]]) { // if (myDelegate.markQuestionTableData.count == 0) { // [DB_Que_Helper moveIsDoneToMarkQuestion];//移动已做题 // if (myDelegate.isLogin)//更新版本 先做一次同步 // { // [self syncQuestion]; // } // } // } // } //监听题库变化 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationAction:) name:@"Tiku_Change" object:nil]; //查看是否在进行集中式理论学习 _isNeedTest = NO; _maxTime = 0; // 注册手势驱动 __weak typeof(self)weakSelf = self; [self cw_registerShowIntractiveWithEdgeGesture:YES transitionDirectionAutoBlock:^(CWDrawerTransitionDirection direction) { if (direction == CWDrawerTransitionFromLeft) { // 左侧滑出 [weakSelf defaultAnimationFromLeft]; } }]; } - (void)notificationAction:(NSNotification *)notification{ self.pagerView.defaultSelectedIndex = 1; self.categoryView.defaultSelectedIndex = 1; [self.pagerView reloadData]; [self.categoryView reloadData]; self.pagerView.isListHorizontalScrollEnabled = ![defUser.isZhiGeZheng isEqualToString:@"YES"]; if ([notification.userInfo[@"zhigezhengChanged"] isEqualToString:@"NO"]) { return; } } /**显示左边抽屉 */ - (void)showLeftViewAction { [self defaultAnimationFromLeft]; } - (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) { _myLocation = location.coordinate; // [self takePhoto]; [self getQgCode]; } }]; } //更新第一次进入同步数据 - (void)syncQuestion { if (![Util connectedToNetWork]) { return; } [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"; [MBProgressHUD rq_showProgressHUD:@"收藏、错题同步中,请稍后..."]; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) { //NSLog(@"同步错题收藏---->%@--->%@",arr,root); if (!root || [root[@"code"] integerValue] == 1) { [MBProgressHUD rq_hideHUD]; ShowMsg(@"题库错题、收藏、排除同步失败,请在侧栏手动同步"); return; } NSArray *body = [root objectForKey:@"body"]; if (body.count > 0) { if ([DB_Que_Helper deleteAllMarkQuestion]) { [DB_Que_Helper setMarkQuestionWithArray:body]; } } [MBProgressHUD rq_hideHUD]; [MBProgressHUD rq_showTips:@"题库错题、收藏、排除已同步完毕"]; }]; } // 仿QQ从左侧划出 - (void)defaultAnimationFromLeft { // 强引用leftVC,不用每次创建新的,也可以每次在这里创建leftVC,抽屉收起的时候会释放掉 // [self cw_showDefaultDrawerViewController:self.leftVC]; CWLateralSlideConfiguration *conf = [CWLateralSlideConfiguration configurationWithDistance:kCWSCREENWIDTH * 0.87 maskAlpha:0.4 scaleY:1 direction:CWDrawerTransitionFromLeft backImage:nil]; // 或者这样调用 [self cw_showDrawerViewController:self.leftVC animationType:CWDrawerAnimationTypeMask configuration:conf]; } #pragma mark - JXPagerViewDelegate - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView { return [UIView new]; } - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView { return 0.f; } - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView { return [defUser.isZhiGeZheng isEqualToString:@"YES"]? 0.f : 49.f; } - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView { return self.categoryView; } - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView { //和categoryView的item数量一致 return self.categoryView.titles.count; } - (id)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index { myDelegate.subject = [NSString stringWithFormat:@"%d",(int)index]; NSInteger myIndex = (index > 0 && index < 5)? index - 1 : 1; RQ_YDTQuestion_Module.subject = myIndex; RQ_SHARE_FUNCTION.myErorNum = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Wrong].count; switch (index) { case 0: { HmV0 *vc = [[HmV0 alloc] init]; return vc; } case 1: case 2: case 3: case 4:{ RQHomePageSubjectOneOrFourViewModel *homePageSubjectFourViewModel = [[RQHomePageSubjectOneOrFourViewModel alloc] initWithServices:self.viewModel.services params:@{RQHomePageCarTypeKey : @(RQHomePageCarType_Car), RQHomePageSubjectTypeKey : @(index - 1)}]; RQHomePageSubjectOneOrFourViewController *homePageSubjectFourViewController = [[RQHomePageSubjectOneOrFourViewController alloc] initWithViewModel:homePageSubjectFourViewModel]; return homePageSubjectFourViewController; } case 5: { HmV5 *vc = [[HmV5 alloc] init]; return vc; } default: return nil; } } #pragma mark - JXCategoryViewDelegate - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index { RQ_YDTQuestion_Module.subject = (index > 0 && index < 5)? index - 1 : 1; RQ_SHARE_FUNCTION.myErorNum = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Wrong].count; myDelegate.subject = [NSString stringWithFormat:@"%d",(int)index]; self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0); } - (void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index { } - (void)categoryView:(JXCategoryBaseView *)categoryView didScrollSelectedItemAtIndex:(NSInteger)index { } #pragma mark - JXPagerMainTableViewGestureDelegate - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { if ([self checkIsNestContentScrollView:(UIScrollView *)gestureRecognizer.view] || [self checkIsNestContentScrollView:(UIScrollView *)otherGestureRecognizer.view]) { //如果交互的是嵌套的contentScrollView,证明在左右滑动,就不允许同时响应 return NO; } return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]; } - (BOOL)checkIsNestContentScrollView:(UIScrollView *)scrollView { for (RQHomeSubPageViewController *list in self.pagerView.validListDict.allValues) { if (list.contentScrollView == scrollView) { return YES; } } return NO; } #pragma mark - SDCycleScrollViewDelegate - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index { } #pragma mark - LazyLoad - (JXPagerView *)pagerView { if (!_pagerView) { _pagerView = [[JXPagerView alloc] initWithDelegate:self]; _pagerView.mainTableView.gestureDelegate = self; _pagerView.defaultSelectedIndex = 1; _pagerView.mainTableView.bounces = NO; } return _pagerView; } - (JXCategoryTitleView *)categoryView { if (!_categoryView) { _categoryView = [[JXCategoryTitleView alloc] init]; _categoryView.titles = self.titles; _categoryView.backgroundColor = [UIColor whiteColor]; _categoryView.titleSelectedColor = RQ_MAIN_TEXT_COLOR_1; _categoryView.titleColor = RQ_MAIN_TEXT_COLOR_2; _categoryView.titleFont = RQRegularFont(13); _categoryView.titleSelectedFont = RQRegularFont(15); _categoryView.titleColorGradientEnabled = YES; _categoryView.titleLabelZoomEnabled = NO; _categoryView.contentScrollViewClickTransitionAnimationEnabled = NO; _categoryView.titleLabelZoomSelectedVerticalOffset = 0.0f; JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init]; lineView.indicatorColor = RQ_MAIN_COLOR; lineView.indicatorHeight = 4; lineView.verticalMargin = 0; _categoryView.indicators = @[lineView]; _categoryView.defaultSelectedIndex = 0; _categoryView.listContainer = (id)self.pagerView.listContainerView; _categoryView.delegate = self; _categoryView.defaultSelectedIndex = 1; } return _categoryView; } - (LeftViewController *)leftVC { if (_leftVC == nil) { _leftVC = [LeftViewController new]; } return _leftVC; } - (NSArray *)titles { return @[@"报名", @"科一", @"科二", @"科三", @"科四", @"拿本"]; } #pragma mark - PrivateMethods //获取当前学员计时状态 - (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)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)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