1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075 |
- /**设置循环滚动
- */
- #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 <BMKLocationkit/BMKLocationComponent.h>//引入定位功能所有的头文件(新)
- #import "OliveappLivenessDetectionViewController.h"
- #import "OliveappCameraPreviewController.h"
- #import "OliveappDetectedFrame.h"
- #import "OliveappBase64Helper.h"
- @interface HomeBaseVC ()<UIScrollViewDelegate,BMKLocationManagerDelegate,OliveappLivenessResultDelegate,FaceDetectorsDelegate>
- {
- /** 分段选择器下方的滚动条。*/
- 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<segItems.count; i ++)
- {
- UIButton * button = [[UIButton alloc]initWithFrame:CGRectMake(segW*i,0,segW,segmenHeight)];
- [button setTitle:[segItems objectAtIndex:i] forState:UIControlStateNormal];
- [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
- [button setTitleColor:defGreen forState:UIControlStateSelected];
- [button.titleLabel setFont:[UIFont scaleSize:15]];
- [button addTarget:self action:@selector(segSelected:) forControlEvents:UIControlEventTouchUpInside];
- [button setBackgroundColor:[UIColor whiteColor]];
- [button setTag:i];
- [self.view addSubview:button];
- [_btns addObject:button];
- }
- barBg = [[UIView alloc] initWithFrame:CGRectMake(0, segmenHeight, kSize.width, barHeight)];
- [barBg setBackgroundColor:backGroundColor];
- [self.view addSubview:barBg];
-
- btnBar = [[UIView alloc] initWithFrame:CGRectMake(segW, segmenHeight, segW, barHeight)];
- [btnBar setBackgroundColor:defGreen];
- [self.view addSubview:btnBar];
-
- //1 addSubView(1+6+1)
- _scroll = [[UIScrollView alloc]init];
- [self.view addSubview:_scroll];
- __block CGFloat scroolY;
- [RACObserve(defUser, isZhiGeZheng) subscribeNext:^(id _Nullable x) {
- 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);
- _scroll.pagingEnabled = YES;
- _scroll.decelerationRate = .2;//用于使scroll快速完成减速。--dansongood
- _scroll.showsHorizontalScrollIndicator = NO;
- _scroll.delegate = self;
- }];
-
-
- /**为了实现页面连滚。
- */
- HmV5* vc05 = [[HmV5 alloc] init];
- vc05.viewH = _scroll.height;
- [self addChildViewController:vc05];
- [_scroll addSubview:vc05.view];
-
-
- //子页面初始化
- HmV0* vc0 = [[HmV0 alloc] init];
- vc0.viewH = _scroll.height;
- [self addChildViewController:vc0];
- [_scroll addSubview:vc0.view];
-
-
- //设置Subject不能在添加之后 因为初始化要用到这个属性
- HmV1* vc1 = [[HmV1 alloc] init];
- vc1.subject = 1;
- vc1.viewH = _scroll.height;
- [self addChildViewController:vc1];
- [_scroll addSubview:vc1.view];
-
-
- HmV2* vc2 = [[HmV2 alloc] init];
- vc2.viewH = _scroll.height;
- [self addChildViewController:vc2];
- [_scroll addSubview:vc2.view];
-
-
- HmV3* vc3 = [[HmV3 alloc] init];
- vc3.viewH = _scroll.height;
- [self addChildViewController:vc3];
- [_scroll addSubview:vc3.view];
-
-
- HmV4* vc4 = [[HmV4 alloc] init];
- vc4.subject = 4;
- vc4.viewH = _scroll.height;
- [self addChildViewController:vc4];
- [_scroll addSubview:vc4.view];
-
-
- HmV5* vc5 = [[HmV5 alloc] init];
- vc5.viewH = _scroll.height;
- [self addChildViewController:vc5];
- [_scroll addSubview:vc5.view];
-
-
- /**为了实现页面连滚。
- */
- HmV0* vc00 = [[HmV0 alloc] initWithFake:YES];
- vc00.viewH = _scroll.height;
- [self addChildViewController:vc00];
- [_scroll addSubview:vc00.view];
- int i = 0;
- for (UIView* v in _scroll.subviews)
- {
- //只需要修改X值,即可
- v.frame = CGRectMake(kSize.width*i++, 0, kSize.width, _scroll.height);
- }
-
- /**考虑到首页VC需要,
- */
- [_scroll setContentSize:CGSizeMake(kSize.height*_scroll.subviews.count, 0)];
-
-
-
- //监听题库变化
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationAction:) name:@"Tiku_Change" object:nil];
- //查看是否在进行集中式理论学习
- isNeedTest = NO;
- maxTime = 0;
-
-
-
- //检测本地是否有学时未上传 如果有不能进行任何操作
- 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];
- }
- }
- }
- - (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
|