123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041 |
- //
- // TheoryTrainVC.m
- // jiaPeiC
- //
- // Created by apple on 2017/2/6.
- // Copyright © 2017年 JCZ. All rights reserved.
- //
- #define dingColor [UIColor colorWithRed:236/255.0 green:190/255.0 blue:44/255.0 alpha:1]
- #import "TheoryTrainVC.h"
- #import "STButton.h"
- #import "Tools.h"
- #import "DES3Util.h"
- #import "UIImageView+WebCache.h"
- #import <BaiduMapAPI_Map/BMKMapComponent.h>//引入地图功能所有的头文件
- #import <BaiduMapAPI_Search/BMKSearchComponent.h>//引入检索功能所有的头文件
- #import <BMKLocationKit/BMKLocationComponent.h>//引入定位功能所有的头文件
- @interface TheoryTrainVC ()<BMKMapViewDelegate,BMKLocationManagerDelegate,BMKGeoCodeSearchDelegate,UITableViewDelegate,UITableViewDataSource,UIAlertViewDelegate,UIActionSheetDelegate>
- {
- UILabel *addressLabel,*detailAddressLabel;
- UIButton *locationBtn;//签到/签退
- UITableView *mainTableView;//地点微调tbvc
- UIButton *ModeifyAddressbtn;//地点微调
-
- UITableView *studentListTV;//学员信息tbvc
- NSMutableArray *_dataurce;//学员信息
-
- UIView *scanView;//二维码视图
- UILabel *scanTypeLable;//二维码标题
- UILabel *timerLabel;//二维码计时lable
- UIImageView *scanImgView;//二维码图片
- NSTimer *timer;
-
- //地图定位
- BMKLocationManager *_locService;
- BMKMapView *_mapView;
- BMKGeoCodeSearch *_searcher;
-
- //数据
- NSArray *poiInfos;
- CLLocationCoordinate2D myLocation;
-
- NSString *scanType;//类型,1签到,2签退,3过程验证
- int timeI;//二维码有效时间限制
- int timePlayAudio;//通知提醒时间间隔(由教练签到接口返回)
- NSInteger currentState;//nil(0)未签到 1实操APP 2模拟 3实操终端 4集中培训 自定义100表示获取失败
-
- }
- @property (nonatomic, strong) BMKUserLocation *userLocation;//当前位置对象
- @end
- @implementation TheoryTrainVC
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self.view setBackgroundColor:backGroundColor];
- self.navigationController.navigationBar.translucent = NO;
-
- if (_isNotification == NO)
- {
- //正常状态
- [self configNavBar];
- }
- else
- {
- //推送状态 要将根视图变回去
- UIBarButtonItem* backBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back.png"] style:UIBarButtonItemStylePlain target:self action:@selector(dismissNavgation)];
- [backBtn setTintColor:defGreen];
- [self.navigationItem setLeftBarButtonItem:backBtn];
- }
-
- _dataurce = [[NSMutableArray alloc]init];
- poiInfos = [[NSMutableArray alloc]init];
- currentState = 100;//未获取当前状态
- scanType = @"";
- timeI = 60*60*24;//不可以太小
- NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
- timePlayAudio = [[ud objectForKey:@"timePlayAudio"] intValue];
-
- [self myInit];
-
- //获取带教/签到状态
- [self getCoachSignStatus];
- [self getStudentTheoryClassesListWithOver:NO];
-
- }
- -(void)dismissNavgation
- {
- [myDelegate gotoLoad];
- }
- -(void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- [_mapView viewWillAppear];
- _mapView.delegate = self; // 此处记得不用的时候需要置nil,否则影响内存的释放
- _searcher.delegate = self;
- _locService.delegate = self;
- }
- -(void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- [_mapView viewWillDisappear];
- _mapView.delegate = nil; // 不用时,置nil
- _searcher.delegate = nil;
- _locService.delegate = nil;
- }
- -(void)viewDidDisappear:(BOOL)animated{
- [super viewDidDisappear:animated];
-
- if (currentState == 0 && timer) {
- [timer invalidate];
- timer = nil;
- }
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- -(void)myInit
- {
- UILabel *label;
- CGFloat x, y, w, h;
- x = 20;
- y = 0;
- w = (kSize.width - 40)/2.0;
- h = 60;
-
- NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
- [formatter setDateFormat:@"yyyy.MM.dd-HH:mm-EEEE"];
- NSString *dateString = [formatter stringFromDate:[NSDate date]];
- //NSLog(@"dateString---->%@",dateString);
- NSArray *dateArray = [NSArray arrayWithObjects:@"暂无",@"暂无",@"暂无", nil];
-
- if (dateString.length > 0) {
- if ([dateString containsString:@"-"]) {
- dateArray = [dateString componentsSeparatedByString:@"-"];
- }
- }
-
-
- label = [[UILabel alloc] setxywh];
- [label setText:[NSString stringWithFormat:@"%@ : %@",[dateArray lastObject],[dateArray firstObject]] Font:Font21 TextColor:contentTextColor Alignment:NSTextAlignmentLeft];
- [self.view addSubview:label];
-
- x += w;
- h = 60;
- label = [[UILabel alloc] setxywh];
- [label setText:[NSString stringWithFormat:@"上课时间:%@\n下课时间:%@",self.startTime,self.endTime] Font:Font17 TextColor:contentTextColor Alignment:NSTextAlignmentRight];
- label.numberOfLines = 0;
- [self.view addSubview:label];
-
- // y += h;
- // label = [[UILabel alloc] setxywh];
- // [label setText:[NSString stringWithFormat:@"下课时间: %@",self.endTime] Font:Font18 TextColor:contentTextColor Alignment:NSTextAlignmentRight];
- // [self.view addSubview:label];
-
- x = 20;
- y += h;
- w = kSize.width - 40;
- h = 100;
-
- UIView *mapBar = [[UIView alloc] setxywh];
- [mapBar borderColor:lineColor width:2 cornorRadios:0];
- mapBar.clipsToBounds = YES;;
- [self.view addSubview:mapBar];
-
- x = y = 0;
- w = 110;
- h = 122;
- //创建地图
- _mapView = [[BMKMapView alloc]setxywh];
- [mapBar addSubview:_mapView];
- [_mapView addViewWithRect:CGRectMake(x + w, y, 2, h)];
-
- _mapView.mapType = BMKMapTypeStandard;
- //定位功能
- _locService = [[BMKLocationManager alloc]init];
- _locService.distanceFilter = 10;
- [_locService startUpdatingLocation];
- //地理位置反编码
- _searcher =[[BMKGeoCodeSearch alloc]init];
-
- //这个设置重复是为了消除一个bug 记得
- _mapView.showsUserLocation = NO;
- _mapView.userTrackingMode = BMKUserTrackingModeNone;
- _mapView.zoomLevel = 16;
- _mapView.showsUserLocation = YES;
-
- BMKLocationViewDisplayParam *displayParam = [[BMKLocationViewDisplayParam alloc]init];
- displayParam.isRotateAngleValid = true;//跟随态旋转角度是否生效
- displayParam.isAccuracyCircleShow = false;//精度圈是否显示
- displayParam.locationViewOffsetX = 0;//定位偏移量(经度)
- displayParam.locationViewOffsetY = 0;//定位偏移量(纬度)
- [_mapView updateLocationViewWithParam:displayParam];
-
-
- x += w + 5;
- w = kSize.width - 40 - 115;
- h = 25;
- label = [[UILabel alloc] setxywh];
- [label setText:@"正在定位..." Font:Font18 TextColor:titleColor Alignment:NSTextAlignmentLeft];
- [mapBar addSubview:label];
- addressLabel = label;
-
- y += h;
- h = 50;
- label = [[UILabel alloc] setxywh];
- [label setText:@"" Font:Font21 TextColor:contentTextColor Alignment:NSTextAlignmentLeft];
- label.numberOfLines = 0;
- [mapBar addSubview:label];
- detailAddressLabel = label;
-
- y += h;
- h = 20;
- UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
- btn.frame = CGRectMake(x, y, w, h);
- [btn setTitle:@"地点微调" textColor:[UIColor blueColor] font:Font18 fotState:UIControlStateNormal];
- [btn setTitle:@"取消微调" forState:UIControlStateSelected];
- btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- [btn.titleLabel setTextAlignment:NSTextAlignmentLeft];
- [btn target:self Tag:1];
- [mapBar addSubview:btn];
- ModeifyAddressbtn = btn;
-
- x = 20;
- y = mapBar.y +mapBar.height + 10;
- w = kSize.width - 40;
- h = 40;
- locationBtn = [[UIButton alloc] initWithFrame:CGRectMake(x, y, w, h)];
- [locationBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [locationBtn setTitle:@"签到" textColor:dingColor font:20 fotState:UIControlStateNormal];
- [locationBtn setTitle:@"签退" textColor:dingColor font:20 fotState:UIControlStateSelected];
- [locationBtn borderColor:dingColor width:1 cornorRadios:5];
- locationBtn.userInteractionEnabled = NO;
- [locationBtn target:self Tag:2];
- [self.view addSubview:locationBtn];
-
- y += h+10;
- CGFloat bd = 20;
- w = (kSize.width-40-bd*2)/3;
-
- NSArray *scanTitles = @[@"学员签到",@"学员签退",@"过程验证"];
- for (int i=0; i<3; i++) {
- x = 20+i*(w + bd);
- btn = [UIButton buttonWithType:UIButtonTypeCustom];
- btn.frame = CGRectMake(x, y, w, h);
- [btn setTitle:scanTitles[i] textColor:lineColor font:20 fotState:UIControlStateNormal];
- [btn borderColor:lineColor width:1 cornorRadios:5];
- [btn target:self Tag:100+i];
- btn.userInteractionEnabled = NO;
- [self.view addSubview:btn];
- }
-
-
- y += h + 10;
- h = kSize.height - y - 64;
- studentListTV = [[UITableView alloc] initWithFrame:CGRectMake(0, y, kSize.width, h) style:UITableViewStylePlain];
- studentListTV.delegate = self;
- studentListTV.dataSource = self;
- studentListTV.tag = 2;
- studentListTV.tableFooterView = [UIView new];
- UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 40)];
- headerView.backgroundColor = lineColor;
- UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, kSize.width - 20, 30)];
- [headerLabel setText:@"班级学员列表" Font:Font21 TextColor:[UIColor orangeColor] Alignment:NSTextAlignmentLeft];
- [headerView addSubview:headerLabel];
-
- [studentListTV setTableHeaderView:headerView];
- [self.view addSubview:studentListTV];
-
- y = mapBar.y +mapBar.height;
- h = kSize.height - y - kNavOffSet;
- mainTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, y, kSize.width, h) style:UITableViewStylePlain];
- mainTableView.delegate = self;
- mainTableView.dataSource = self;
- mainTableView.tag = 1;
- [self.view addSubview:mainTableView];
- mainTableView.hidden = YES;
- }
- -(void)btnClick:(UIButton *)sender
- {
- if (sender.tag == 1) {
- //微调
- sender.selected = !sender.selected;
-
- if (sender.selected) {
- mainTableView.hidden = NO;
- [mainTableView reloadData];
- }else{
- mainTableView.hidden = YES;
- }
- return;
- }
- if (sender.tag == 2) {
-
-
- if (sender.selected) {
-
- //签退
-
- }else{
-
- //签到
- if (currentState == 100) {
- //获取带教/签到状态
- [self getCoachSignStatus];
- return;
- }
-
- if (currentState) {
- ShowMsg(@"当前正在进行其它(实操/模拟)计时,请结束后再进行理论计时");
- return;
- }
-
- if (!myLocation.latitude) {
-
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"未获取到当前位置" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"再试一次", nil];
- [alert show];
- return;
- }
- }
-
- [self uploadAppSignInfo];
- return;
- }
-
- //生成二维码
- switch (sender.tag) {
- case 100:
- {
- BOOL isNeed = YES;
- for (NSDictionary *dic in _dataurce) {
- if ([[NSString stringWithFormat:@"%@",dic[@"STATUS"]] integerValue] == 1) {
- isNeed = NO;
- break;
- }
- }
- if (isNeed) {
- [self removeAllTheoryNotify];//先移除已经存在的
- [self addLocalNotification];//开启本地通知提醒
- }
-
- scanType = @"1";
- [self getQrcode];
- }
- break;
- case 101:
- {
- scanType = @"2";
- [self getQrcode];
- }
- break;
- case 102:
- {
- scanType = @"3";
- [self getQrcode];
- }
- break;
-
- default:
- break;
- }
- }
- -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
- {
- if (buttonIndex == 0) {
-
- }else{
- if (_locService) {
- //前面定位无数据,定位再试一次
- [_locService stopUpdatingLocation];
- [_locService startUpdatingLocation];
- }
- }
- }
- #pragma mark tableView delegate
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- if (tableView.tag == 1) {
- return poiInfos.count;
- }else{
- return _dataurce.count;
- }
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (tableView.tag == 1) {
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
- if (cell == nil)
- {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
- }
- BMKPoiInfo *poiInfo = poiInfos[indexPath.row];
-
- cell.textLabel.text = poiInfo.name;
- cell.textLabel.textColor = titleColor;
- cell.textLabel.font = [UIFont scaleSize:Font18];
-
- cell.detailTextLabel.text = poiInfo.address;
- cell.detailTextLabel.textColor = contentTextColor;
- cell.detailTextLabel.font = [UIFont scaleSize:Font18];
- return cell;
-
- }else{
-
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellid"];
- if (!cell) {
- cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellid"];
- }
- cell.textLabel.text = [NSString stringWithFormat:@"%@",_dataurce[indexPath.row][@"TSC_STUDENT_NAME"]];
- NSString *stuStr = @"";
- switch ([[NSString stringWithFormat:@"%@",_dataurce[indexPath.row][@"STATUS"]] integerValue]) {
- case 0:
- stuStr = @"未学习";
- cell.detailTextLabel.textColor = contentTextColor;
- break;
- case 1:
- stuStr = @"学习中";
- cell.detailTextLabel.textColor = dingColor;
- break;
- case 2:
- stuStr = @"学习结束";
- cell.detailTextLabel.textColor = contentTextColor;
- break;
- default:
- break;
- }
- cell.detailTextLabel.text = stuStr;
-
- return cell;
- }
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (tableView.tag == 1) {
- BMKPoiInfo *info = poiInfos[indexPath.row];
-
- addressLabel.text = info.name;
- detailAddressLabel.text = info.address;
- _mapView.centerCoordinate = info.pt;
-
- myLocation = info.pt;
-
- //加标注之前要移除之前的
- if (_mapView.annotations.count > 0) {
- [_mapView removeAnnotations:_mapView.annotations];
- }
- //选择的位置加上标注
- BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
- annotation.coordinate = info.pt;
- [_mapView addAnnotation:annotation];
-
- mainTableView.hidden = YES;
- ModeifyAddressbtn.selected = NO;
- }
- }
- #pragma mark 地图相关
- /**用户拒绝开启定位服务等原因导致的定位失败会调用的方法
- */
- - (void)didFailToLocateUserWithError:(NSError *)error
- {
- //[LoadingView showMsg:@"拒绝将无法自动获取当前位置!"];
- UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请在iPhone的“设置”-“隐私”-“定位服务”功能中,找到“优易学车”打开位置访问权限" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
- [alert show];
- locationBtn.userInteractionEnabled = YES;
- }
- //处理位置坐标更新
- - (void)BMKLocationManager:(BMKLocationManager *)manager didUpdateLocation:(BMKLocation *)location orError:(NSError *)error {
- self.userLocation.location = location.location;
- if (self.userLocation.location)
- {
- [_mapView updateLocationData:self.userLocation];
- _mapView.centerCoordinate = self.userLocation.location.coordinate;
-
- myLocation = self.userLocation.location.coordinate;
-
-
- //发起反向地理编码检索
- BMKReverseGeoCodeSearchOption *reverseGeoCodeSearchOption = [[BMKReverseGeoCodeSearchOption alloc]init];
- reverseGeoCodeSearchOption.location = location.location.coordinate;
- [_searcher reverseGeoCode:reverseGeoCodeSearchOption];
- }
- }
- - (void)onGetGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKGeoCodeSearchResult *)result errorCode:(BMKSearchErrorCode)error {
- if (error == BMK_SEARCH_NO_ERROR) {
- //在此处理正常结果
- BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
-
- annotation.coordinate = result.location;
- [_mapView addAnnotation:annotation];
- }
- else {
- [LoadingView showMsg:@"定位失败!"];
- }
- }
- //反向编码
- - (void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeSearchResult *)result errorCode:(BMKSearchErrorCode)error {
- searcher.delegate = nil;
- locationBtn.userInteractionEnabled = YES;
- if (error == BMK_SEARCH_NO_ERROR)
- {
- // 商业圈 businessCircle
- // 街道号码 streetNumber
- // 街道名称 streetName
- // 区县名称 district
- // 城市名称 city
- // 省份名称 province;
- // 地址全称 address
- //地址周边POI信息,成员类型为BMKPoiInfo poiList
- /*
- NSString* _name; ///<POI名称
- NSString* _uid;
- NSString* _address; ///<POI地址
- NSString* _city; ///<POI所在城市
- NSString* _phone; ///<POI电话号码
- NSString* _postcode; ///<POI邮编
- int _epoitype; ///<POI类型,0:普通点 1:公交站 2:公交线路 3:地铁站 4:地铁线路
- CLLocationCoordinate2D _pt; ///<POI坐标
- */
-
- //NSLog(@"---->%@---->%@---->%@---->%@---->%@---->%@----->%@",result.addressDetail.streetNumber,result.addressDetail.streetName,result.addressDetail.district,result.addressDetail.city,result.addressDetail.province,result.address,result.poiList);
-
- //在此处理正常结果
- addressLabel.text = [NSString stringWithFormat:@"%@%@%@",result.addressDetail.district,result.addressDetail.streetName,result.addressDetail.streetNumber];
- //默认这个地址作为签到地址
- detailAddressLabel.text = result.address;
-
- //将周边存起来 微调的时候用
- poiInfos = result.poiList;
- }
- else
- {
- //[LoadingView showMsg:@"编译位置失败!"];
- }
- }
- //标注的代理
- -(BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation
- {
- if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
- BMKPinAnnotationView *newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];
- newAnnotationView.pinColor = BMKPinAnnotationColorPurple;
- // 设置该标注点动画显示
- newAnnotationView.animatesDrop = NO;
- return newAnnotationView;
- }
- return nil;
- }
- #pragma mark 生成二维码
- -(void)makeScanViewWithScanString:(NSString *)qgStr
- {
-
- //生成二维码
- NSString *typeStr = @"";
- NSString *signType = @"";
- switch ([scanType integerValue]) {
- case 1:
- {
- typeStr = @"groupSignIn";
- signType = @"学员签到二维码";
-
- if (!timer) {
- timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeRun) userInfo:nil repeats:YES];
- [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
- }
- }
- break;
- case 2:
- typeStr = @"groupSignOut";
- signType = @"学员签退二维码";
- break;
- case 3:
- {
- typeStr = @"groupSignProceed";
- signType = @"学员过程验证二维码";
- }
- break;
- default:
- break;
- }
-
- NSString *scanString = [NSString stringWithFormat:@"#LNJP#;%@;%@",typeStr,[DES3Util decrypt:qgStr]];
- // NSLog(@"加密前---><>%@",scanString);
- scanString = [DES3Util encrypt:scanString];
- scanString = [NSString stringWithFormat:@"#DECODE#%@",scanString];
-
- UIImage *qrcode = [self createNonInterpolatedUIImageFormCIImage:[self createQRForString:scanString] withSize:250.0f];
- qrcode = [self addIconToQRCodeImage:qrcode withIcon:[UIImage imageNamed:@"loginLogo"] withIconSize:CGSizeMake(40, 40)];
- //非第一次,只需更新img
- if (scanView) {
- if (!scanView.superview) {
- [self.view addSubview:scanView];
- }
- scanTypeLable.text = signType;
- timerLabel.text = [NSString stringWithFormat:@"二维码有效时间:%d:%d",timeI/60,timeI%60];
- scanImgView.image = qrcode;
- return;
- }
-
- CGFloat x,y,w,h;
- x = 20;
- y = 100;
- w = kSize.width - 40;
- h = kSize.width + 20;
- scanView = [[UIView alloc] setxywh];
- scanView.backgroundColor = [UIColor whiteColor];
- [scanView borderColor:lineColor width:1 cornorRadios:5];
- [self.view addSubview:scanView];
-
- x = 0;
- y = 0;
- h = 30;
- UILabel *label = [[UILabel alloc] setxywh];
- [label setText:signType Font:Font16 TextColor:[UIColor orangeColor] Alignment:NSTextAlignmentCenter];
- [scanView addSubview:label];
- scanTypeLable = label;
-
-
- x = (w - 250)/2.0;
- y += h + 10;
- w = h = 250;
- scanImgView = [[UIImageView alloc] setxywh];
- scanImgView.image = qrcode;
- [scanView addSubview:scanImgView];
-
- x = 0;
- y += h + 10;
- w = kSize.width - 40;
- h =30;
- label = [[UILabel alloc] setxywh];
- [label setText:[NSString stringWithFormat:@"二维码有效时间:%d:%d",timeI/60,timeI%60] Font:Font16 TextColor:[UIColor orangeColor] Alignment:NSTextAlignmentCenter];
- [scanView addSubview:label];
- timerLabel = label;
-
- UIImageView *cancelImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cancel"]];
- cancelImg.frame = CGRectMake(w - 25, 5, 20, 20);
- [scanView addSubview:cancelImg];
-
- UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
- btn.frame = CGRectMake(w - 50, 0, 50, 50);
- btn.backgroundColor = [UIColor clearColor];
- [btn addTarget:self action:@selector(removeScanView) forControlEvents:UIControlEventTouchUpInside];
- [scanView addSubview:btn];
- }
- -(void)removeScanView
- {
- [scanView removeFromSuperview];
-
- [self getStudentTheoryClassesListWithOver:YES];
- }
- //二维码的验证
- -(void)timeRun
- {
- timeI --;
- timerLabel.text = [NSString stringWithFormat:@"二维码有效时间:%d:%d",timeI/60,timeI%60];
-
- if (timeI == 0) {
- //重新生成二维码
- [self getQrcode];
- }
- }
- - (CIImage *)createQRForString:(NSString *)qrString {
- NSData *stringData = [qrString dataUsingEncoding:NSUTF8StringEncoding];
- // 创建filter
- CIFilter *qrFilter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
- // 设置内容和纠错级别
- [qrFilter setValue:stringData forKey:@"inputMessage"];
- [qrFilter setValue:@"M" forKey:@"inputCorrectionLevel"];
- // 返回CIImage
- return qrFilter.outputImage;
- }
- - (UIImage *)createNonInterpolatedUIImageFormCIImage:(CIImage *)image withSize:(CGFloat) size {
- CGRect extent = CGRectIntegral(image.extent);
- CGFloat scale = MIN(size/CGRectGetWidth(extent), size/CGRectGetHeight(extent));
- // 创建bitmap;
- size_t width = CGRectGetWidth(extent) * scale;
- size_t height = CGRectGetHeight(extent) * scale;
- CGColorSpaceRef cs = CGColorSpaceCreateDeviceGray();
- CGContextRef bitmapRef = CGBitmapContextCreate(nil, width, height, 8, 0, cs, (CGBitmapInfo)kCGImageAlphaNone);
- CIContext *context = [CIContext contextWithOptions:nil];
- CGImageRef bitmapImage = [context createCGImage:image fromRect:extent];
- CGContextSetInterpolationQuality(bitmapRef, kCGInterpolationNone);
- CGContextScaleCTM(bitmapRef, scale, scale);
- CGContextDrawImage(bitmapRef, extent, bitmapImage);
- // 保存bitmap到图片
- CGImageRef scaledImage = CGBitmapContextCreateImage(bitmapRef);
- CGColorSpaceRelease(cs);
- CGContextRelease(bitmapRef);
- CGImageRelease(bitmapImage);
- UIImage * newImage = (UIImage *)[UIImage imageWithCGImage:scaledImage];
- CGImageRelease(scaledImage);
- return newImage;
- }
- -(UIImage *)addIconToQRCodeImage:(UIImage *)image withIcon:(UIImage *)icon withIconSize:(CGSize)iconSize {
- UIGraphicsBeginImageContext(image.size);
- //通过两张图片进行位置和大小的绘制,实现两张图片的合并;其实此原理做法也可以用于多张图片的合并
- CGFloat widthOfImage = image.size.width;
- CGFloat heightOfImage = image.size.height;
- CGFloat widthOfIcon = iconSize.width;
- CGFloat heightOfIcon = iconSize.height;
-
- [image drawInRect:CGRectMake(0, 0, widthOfImage, heightOfImage)];
- [icon drawInRect:CGRectMake((widthOfImage-widthOfIcon)/2, (heightOfImage-heightOfIcon)/2,
- widthOfIcon, heightOfIcon)];
- UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
-
- UIGraphicsEndImageContext();
- return img;
- }
- #pragma mark - 添加本地通知
- -(void)addLocalNotification{
- //下课时间
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
- NSString *nowStr = [dateFormatter stringFromDate:[NSDate date]];
- NSDate *endDate = [dateFormatter dateFromString:[NSString stringWithFormat:@"%@ %@:00",[nowStr substringToIndex:10],self.endTime]];
-
- for (int i=1; i<=60*60*4/timePlayAudio; i++) {
- //定义本地通知对象
- UILocalNotification *notification=[[UILocalNotification alloc]init];
- //设置调用时间
- notification.fireDate=[NSDate dateWithTimeIntervalSinceNow:timePlayAudio*i];
- NSTimeInterval subT = [endDate timeIntervalSinceDate:notification.fireDate];
- if (subT < 0) {
- NSLog(@"%@,%@",notification.fireDate,[NSDate dateWithTimeIntervalSinceNow:timePlayAudio*i]);
- break;
- }
-
- //设置通知属性
- notification.alertBody=@"请提醒学员扫描过程验证二维码"; //通知主体
- notification.applicationIconBadgeNumber=1;//应用程序图标右上角显示的消息数
- notification.alertAction=@"打开应用"; //待机界面的滑动动作提示
- notification.soundName=@"TheoryNotify.mp3";//收到通知时播放的声音,默认消息声音
- // 通知参数
- NSDictionary *userDict = [NSDictionary dictionaryWithObjectsAndKeys:self.classId,@"theoryTrainVC_classId",self.schoolId,@"theoryTrainVC_schoolId", nil];
- notification.userInfo = userDict;
- //调用通知
- [[UIApplication sharedApplication] scheduleLocalNotification:notification];
- }
-
- }
- -(void)removeAllTheoryNotify{
- NSArray *notifiArray = [[UIApplication sharedApplication] scheduledLocalNotifications];
- for (UILocalNotification *local in notifiArray) {
- if (local.userInfo[@"theoryTrainVC_classId"]) {
- //删除单个通知
- [[UIApplication sharedApplication]cancelLocalNotification:local];
- }
- }
-
- }
- #pragma mark 数据请求
- - (void)getCoachSignStatus
- {
- [LoadingView showHUD];
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableArray *arr=[NSMutableArray array];
-
- [arr addPro:@"coachOutId" Value:defUser.userDict[@"outId"]];
- [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]];
-
- NSString* method = @"getCoachSignStatus";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
- RemoveHUD();
- if (!root) {
- return;
- }
- if ([root[@"code"] isEqualToString:@"1"]) {
- ShowMsg(root[@"body"]);
- return;
- }
-
- NSInteger states = [root[@"body"] integerValue];
- if (!states) {
- states = 0;
- }
- //0未签到 1实操APP 2模拟 3实操终端 4集中培训
-
- if (states == 2 || states == 3) {
- UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:@"当前正在进行其它(实操/模拟)计时,请结束后再进行理论计时" preferredStyle:UIAlertControllerStyleAlert];
-
- [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
- [self.navigationController popViewControllerAnimated:YES];
- }]];
- [self presentViewController:alertFind animated:true completion:nil];
- }else{
- locationBtn.selected = states;
- for (int i=100; i<103; i++) {
- UIButton *scanBtn = (UIButton *)[self.view viewWithTag:i];
- if (locationBtn.selected) {
- //签到状态
- [scanBtn setTitleColor:dingColor forState:UIControlStateNormal];
- scanBtn.layer.borderColor = dingColor.CGColor;
- scanBtn.userInteractionEnabled = YES;
-
- }else{
- //签退状态
- [scanBtn setTitleColor:lineColor forState:UIControlStateNormal];
- scanBtn.layer.borderColor = lineColor.CGColor;
- scanBtn.userInteractionEnabled = NO;
-
- };
- }
- }
-
- currentState = states;
-
- if (currentState == 4) {
- if (!timer) {
- timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeRun) userInfo:nil repeats:YES];
- [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
- }
- }
-
- }];
- }
- - (void)uploadAppSignInfo
- {
- [LoadingView showHUD];
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSString *type = locationBtn.selected ? @"2" : @"1";
-
- NSMutableArray *arr = [[NSMutableArray alloc]init];
- [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]];
- [arr addPro:@"classId" Value:self.classId];
- [arr addPro:@"coachOutid" Value:defUser.userDict[@"outId"]];
- [arr addPro:@"schoolOutid" Value:self.schoolId];
- [arr addPro:@"type" Value:type];//类型,1签到,2签退
- [arr addPro:@"lng" Value:[NSString stringWithFormat:@"%f",myLocation.longitude]];
- [arr addPro:@"lat" Value:[NSString stringWithFormat:@"%f",myLocation.latitude]];
- NSString *method = @"coachTheorySign";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
- RemoveHUD();
-
- if (!root) {
-
- if ([type isEqualToString:@"1"]) {
- ShowMsg(@"签到失败,请重试");
- [Tools playAudioWithString:@"签到失败,请虫试"];
- }else{
- ShowMsg(@"签退失败,请重试");
- [Tools playAudioWithString:@"签退失败,请虫试"];
- }
- return;
- }
-
- if (![root[@"code"] isEqualToString:@"0"]) {
-
- ShowMsg(root[@"body"]);
- return;
- }
-
- if ([type isEqualToString:@"1"]) {
-
- [Tools playAudioWithString:@"签到成功"];
- timePlayAudio = [root[@"body"] intValue];
- NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
- [ud setObject:[NSString stringWithFormat:@"%d",timePlayAudio] forKey:@"timePlayAudio"];
- [ud synchronize];
-
- }else{
-
- [Tools playAudioWithString:@"签退成功"];
- [self removeAllTheoryNotify];
- }
-
-
- locationBtn.selected = !locationBtn.selected;
- currentState = locationBtn.selected ? 4 : 0;
- for (int i=100; i<103; i++) {
- UIButton *scanBtn = (UIButton *)[self.view viewWithTag:i];
- if (locationBtn.selected) {
- [scanBtn setTitleColor:dingColor forState:UIControlStateNormal];
- scanBtn.layer.borderColor = dingColor.CGColor;
- scanBtn.userInteractionEnabled = YES;
- }else{
- [scanBtn setTitleColor:lineColor forState:UIControlStateNormal];
- scanBtn.layer.borderColor = lineColor.CGColor;
- scanBtn.userInteractionEnabled = NO;
- };
- }
-
- }];
- }
- /**
- 获取班级学员列表
- @param isOver 如果=yes,表示关闭二维码调用,需要判定是否还有学员在学习,如果没有则移除所有通知。=No表示初始化进来获取学员列表信息,无需判断是否需要移除通知,其实判断一下也是可以的,先这样吧
- */
- -(void)getStudentTheoryClassesListWithOver:(BOOL)isOver{
-
- [LoadingView showHUD];
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableArray *arr = [[NSMutableArray alloc]init];
- [arr addPro:@"classId" Value:_classId];
- [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]];
- NSString *method = @"getStudentTheoryClassesList";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
- RemoveHUD();
- if (!root) {
- ShowMsg(@"数据请求失败,请重试");
- return;
- }
- if ([root[@"code"] integerValue] == 1) {
- ShowMsg(root[@"msg"]);
- return;
- }
- _dataurce = root[@"body"];
- [studentListTV reloadData];
-
- //如果二维码关闭,则判断下是否需要移除通知
- if (isOver) {
- //遍历学员,如果有任何一个学员还在学习中,我们就不移除通知提醒
- BOOL isNeed = YES;
- for (NSDictionary *dic in _dataurce) {
- if ([[NSString stringWithFormat:@"%@",dic[@"STATUS"]] integerValue] == 1) {
- isNeed = NO;
- break;
- }
- }
- if (isNeed) {
- [self removeAllTheoryNotify];//先移除已经存在的
- }
- }
- }];
- }
- -(void)getQrcode{
-
- [LoadingView showHUD];
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- if (!myLocation.latitude) {
-
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"未获取到当前位置" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"再试一次", nil];
- [alert show];
- return;
- }
-
- NSMutableArray *arr = [[NSMutableArray alloc]init];
- [arr addPro:@"dqbh" Value:defUser.userDict[@"cityId"]];
- [arr addPro:@"classId" Value:self.classId];
- [arr addPro:@"coachOutid" Value:defUser.userDict[@"outId"]];
- [arr addPro:@"type" Value:scanType];//类型,1签到,2签退,3过程验证
- [arr addPro:@"lng" Value:[NSString stringWithFormat:@"%f",myLocation.longitude]];
- [arr addPro:@"lat" Value:[NSString stringWithFormat:@"%f",myLocation.latitude]];
- NSString *method = @"getQrcode";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
- RemoveHUD();
-
- if (!root) {
-
- ShowMsg(@"数据请求失败,请重试");
- if (scanView) {
- [self removeScanView];
- }
- return;
- }
-
- if (![root[@"code"] isEqualToString:@"0"]) {
-
- ShowMsg(root[@"body"]);
- return;
- }
-
- NSArray *arr = [root[@"body"] componentsSeparatedByString:@"@@@"];
- timeI = [arr[0] intValue];
- [self makeScanViewWithScanString:arr[1]];
-
- // NSLog(@"%@--%@",root[@"body"],[DES3Util decrypt:arr[1]]);
-
- }];
-
- }
- #pragma mark - LazyLoad
- - (BMKUserLocation *)userLocation {
- if (!_userLocation) {
- _userLocation = [[BMKUserLocation alloc] init];
- }
- return _userLocation;
- }
- @end
|