BigTruckVC.m 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633
  1. //
  2. // BigTruckVC.m
  3. // jiaPei
  4. //
  5. // Created by EchoShacolee on 2018/4/3.
  6. // Copyright © 2018年 JCZ. All rights reserved.
  7. //
  8. /*
  9. 中途/首次连接流程:
  10. 手机主动发起连接请求指令RequestConnectOrder(包含学员全国统一编号);终端判断回复be020400成功,be020401非当前学员失败
  11. 期间由心跳包保持连接 中断心跳包指令be0501... ;app回复 HeartbeatOrder
  12. 签退:终端签退通知手机指令:QuitOrder,若手机不在附近 手机会在每5分钟更新学员状态的地方知道自己已被签退 停止计时
  13. 本地学时补传:nextWithCurrentStatu 里面根据当前是否准备计时来判断是立即提示补传或者等开始计时后的第一分钟跟随上传
  14. 状态接口没300s调一次。1.更新UI 2.检测状态。如果检测到学员在终端已签退。则执行签退相关的操作
  15. 状态接口1:getCurrentState 更新训练状态 更新训练过程图片
  16. 状态接口2:getStudentTrainInfos 更新训练信息
  17. */
  18. #import "BigTruckVC.h"
  19. #import <CoreBluetooth/CoreBluetooth.h>
  20. #import <BaiduMapAPI_Utils/BMKUtilsComponent.h>//bd计算相关
  21. #import "TileViewController.h"
  22. #import "EleMinRecordListVC.h"
  23. #import <MJRefresh.h>
  24. #import "BC_TimerImgView.h"
  25. static NSString * const bigCarTableName = @"dcPeriod";
  26. static NSString * const BServiceUUID = @"6E400001-B5A3-F393-E0A9-E50E24DCCA9E";
  27. static NSString * const BCharacteristicUUID_write = @"6E400002-B5A3-F393-E0A9-E50E24DCCA9E";
  28. static NSString * const BCharacteristicUUID_reade = @"6E400003-B5A3-F393-E0A9-E50E24DCCA9E";
  29. static NSString * const RequestConnectOrder = @"be0984";//请求连接
  30. static NSString * const HeartbeatOrder = @"be03810000";//心跳回应
  31. static NSString * const QuitOrder = @"be0183";//签退指令
  32. @interface BigTruckVC ()<CLLocationManagerDelegate,CBCentralManagerDelegate,CBPeripheralDelegate>
  33. {
  34. BOOL hasReply; //蓝牙命令已回复
  35. BOOL isVoice; //是否开启语音提醒 默认开启
  36. NSDateFormatter *dateFormatter;
  37. NSMutableDictionary *minuteTrainDic;//分钟学时用参数 签到和断线重连时候初始化 分钟学时发送之前更新字典
  38. NSMutableDictionary *gatherTrainDic;//汇总学时用参数 签到和断线重连时候初始化 分钟学时发送之前更新字典 并存本地 短线重连用来恢复计时
  39. //地图定位
  40. CLLocationCoordinate2D myCoordinate;//定位我的位置
  41. NSMutableDictionary *gpsDic; //某个点的信息
  42. CLLocationManager *locationManager;//系统gps
  43. NSTimer *timer;
  44. NSInteger seconds; //定时器时间
  45. //蓝牙
  46. BOOL dataIsLack;//如果为yes代表数据不完整 需要下次接收到的数据拼接
  47. NSString *lastData;//接收蓝牙数据时 一个数据包分次返回时 之前的数据
  48. NSString *peripheralName;//蓝牙名称
  49. NSString *blueToothOrder;//最新的蓝牙命令 用于蓝牙未回应重新作操作
  50. BOOL isConnectBlueTooth;//是否与蓝牙连接状态
  51. NSInteger disconnectSeconds;//蓝牙断开的时长
  52. //学时相关
  53. NSString *subject; //当前训练科目
  54. NSString *classId; //课堂ID
  55. NSString *trainOrderNum;//学时编号用序列 每天置0
  56. NSMutableArray<NSString *> *dataSourceArray; //表的数据源 组成部分:颜色数字+提示字 1为红色失败 2为绿色成功(暂未使用)
  57. NSDictionary *bigCarDic;//状态接口返回数据
  58. //UI
  59. UIScrollView *mainScrV;
  60. //statusLab
  61. UILabel *statusLab;//调试用@lee
  62. //top
  63. UILabel *nameLab;
  64. UILabel *coachLab;
  65. UILabel *carNum;
  66. BC_TimerImgView *topRight;
  67. NSMutableArray *trainMsgLabs;//培训信息lab集合
  68. UILabel *trainDetails;
  69. //培训照片
  70. UIButton *checkTrainPhotoBtn;//查看培训照片
  71. UIView *tileView;//照片视图
  72. }
  73. //蓝牙
  74. @property (nonatomic, strong) CBCentralManager *cbcManager;
  75. /** 已连接的外设*/
  76. @property (nonatomic, strong) CBPeripheral *peripheral;
  77. /** 要写入的特征值*/
  78. @property (nonatomic, strong) CBCharacteristic *writeCharacteristic;
  79. /** 要读的特征值*/
  80. @property (nonatomic, strong) CBCharacteristic *readCharacteristic;
  81. @property (nonatomic, strong) UILabel *blueToothLabel;
  82. @end
  83. @implementation BigTruckVC
  84. - (void)viewDidLoad {
  85. [super viewDidLoad];
  86. self.title = @"大客/货车计时";
  87. self.view.backgroundColor = backGroundColor;
  88. [self customNavigationBar];
  89. //ui
  90. [self myInit];
  91. //开启定位(设置允许后台定位)
  92. [self setGPSLocationService];
  93. //获取当前状态
  94. [self getCurrentState];
  95. }
  96. -(void)viewDidDisappear:(BOOL)animated{
  97. [super viewDidDisappear:animated];
  98. if (timer == nil) {
  99. [locationManager stopUpdatingLocation];
  100. }
  101. [self.blueToothLabel removeFromSuperview];
  102. }
  103. - (void)didReceiveMemoryWarning {
  104. [super didReceiveMemoryWarning];
  105. // Dispose of any resources that can be recreated.
  106. }
  107. - (void)myInit{
  108. dateFormatter = [NSDateFormatter rq_defaultDateFormatter];
  109. gatherTrainDic = [NSMutableDictionary dictionary];
  110. trainMsgLabs = [NSMutableArray array];
  111. mainScrV = [[UIScrollView alloc]initWithFrame:kFrame];
  112. mainScrV.height -= kNavOffSet;
  113. [self.view addSubview:mainScrV];
  114. //下啦刷新
  115. MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  116. [self getCurrentState];
  117. [mainScrV.mj_header endRefreshing];//这个就放这里吧
  118. }];
  119. mainScrV.mj_header = header;
  120. CGFloat x,y,w,h;
  121. x = 0;
  122. y = 0;
  123. h = 100;
  124. w = kSize.width;
  125. //@lee 调试用状态栏
  126. // {
  127. // h = 130;
  128. // UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(0, h-30, kSize.width, 30)];
  129. // statusLab = lab;
  130. // lab.alpha = .7;
  131. // lab.backgroundColor = [UIColor yellowColor];
  132. // [mainScrV addSubview:lab];
  133. // }
  134. //topView
  135. UIImageView *topView =[[UIImageView alloc]setxywh];
  136. topView.backgroundColor = [UIColor darkGrayColor];
  137. // topView.image = [UIImage imageNamed:@"bigCar_TrainTop"];
  138. [mainScrV addSubview:topView];
  139. x = 20;
  140. w = 80;
  141. h = 100;
  142. y = (h-w)/2;
  143. UIImageView *headV = [[UIImageView alloc]initWithFrame:CGRectMake(20, y, w, w)];
  144. headV.layer.masksToBounds = YES;
  145. headV.layer.cornerRadius = w/2;
  146. [topView addSubview:headV];
  147. NSString *str = defUser.userDict[@"photo"];
  148. if (str == nil) {
  149. str = @"";
  150. }
  151. [headV sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"drawer_head.png"]];
  152. x += x+w;
  153. h = w/3;
  154. w = kSize.width - x - 20;
  155. nameLab = [[UILabel alloc]setxywh];
  156. [nameLab setText:defUser.userDict[@"userName"] Font:FontTitle TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentLeft];
  157. [topView addSubview:nameLab];
  158. y += h;
  159. coachLab = [[UILabel alloc]setxywh];
  160. [coachLab setText:@"带教教练:" Font:FontTitle TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentLeft];
  161. [topView addSubview:coachLab];
  162. y += h;
  163. carNum = [[UILabel alloc]setxywh];
  164. [carNum setText:@"未开始计时" Font:FontTitle TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentLeft];
  165. [topView addSubview:carNum];
  166. topRight = [BC_TimerImgView buttonWithType:UIButtonTypeCustom];
  167. [topRight setTitle:@"计时中" forState:UIControlStateNormal];
  168. [topRight setTitle:@"计时停止" forState:UIControlStateSelected];
  169. [topRight setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  170. [topRight setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
  171. [topRight.titleLabel setTextAlignment:NSTextAlignmentCenter];
  172. [topRight.titleLabel setAdjustsFontSizeToFitWidth:YES];
  173. [topRight setImage:[[UIImage imageNamed:@"bigCar_clock"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
  174. [topRight setImage:[[UIImage imageNamed:@"bigCar_clock"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateSelected];
  175. topRight.frame = CGRectMake(kSize.width-100, 10, 60, 60*3/2);
  176. topRight.alpha = 0;
  177. [topView addSubview:topRight];
  178. //培训信息
  179. x = 10;
  180. y = topView.height;
  181. w = kSize.width;
  182. h = 50;
  183. UILabel *trainMessageLab = [[UILabel alloc]setxywh];
  184. [trainMessageLab setText:@"培训信息" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
  185. [mainScrV addSubview:trainMessageLab];
  186. w = 110;
  187. h = 35;
  188. x = kSize.width - w-15;
  189. y += (trainMessageLab.height-h)/2;
  190. UIButton *checkMinRecordBtn = [UIButton buttonWithType:UIButtonTypeSystem];
  191. checkMinRecordBtn.layer.masksToBounds = YES;
  192. checkMinRecordBtn.layer.cornerRadius = 5;
  193. checkMinRecordBtn.frame = CGRectMake(x, y, w, h);
  194. [checkMinRecordBtn setTitle:@"查看分钟学时" textColor:[UIColor whiteColor] font:FontTitle fotState:UIControlStateNormal];
  195. [checkMinRecordBtn addTarget:self action:@selector(checkMinRecordBtnClick) forControlEvents:UIControlEventTouchUpInside];
  196. checkMinRecordBtn.backgroundColor = defGreen;
  197. [mainScrV addSubview:checkMinRecordBtn];
  198. x = 0;
  199. y += (trainMessageLab.height-h)/2+h;
  200. w = kSize.width;
  201. h = 3;
  202. [trainMessageLab addViewWithRect:CGRectMake(x, y, w, h) Color:defGreen];
  203. x = 0;
  204. y += h+15;
  205. w = kSize.width/4;
  206. h = 30;
  207. CGFloat bd = 15;
  208. for (int i=0; i<4; i++) {
  209. for (int j=0; j<7; j++) {
  210. UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(i%4*w, y+j%7*h, w, h)];
  211. if (j>=5) {
  212. lab.frame = CGRectMake(i%4*w, bd+y+j%7*h, w, h);
  213. }
  214. lab.font = [UIFont scaleSize:Font17];
  215. lab.adjustsFontSizeToFitWidth = YES;
  216. lab.textAlignment = NSTextAlignmentCenter;
  217. [mainScrV addSubview:lab];
  218. if (j==0) {
  219. lab.textColor = kTitleColor;
  220. switch (i) {
  221. case 0:
  222. lab.text = @"培训阶段";
  223. break;
  224. case 1:
  225. lab.text = @"已完成学时";
  226. break;
  227. case 2:
  228. lab.text = @"审核状态";
  229. break;
  230. case 3:
  231. lab.text = @"确认状态";
  232. break;
  233. default:
  234. break;
  235. }
  236. }else if (i==0){
  237. lab.textColor = kTitleColor;
  238. switch (j) {
  239. case 1:
  240. lab.text = @"科目一";
  241. break;
  242. case 2:
  243. lab.text = @"科目二";
  244. break;
  245. case 3:
  246. lab.text = @"科目三";
  247. break;
  248. case 4:
  249. lab.text = @"科目四";
  250. break;
  251. case 5:
  252. lab.text = @"总时长";
  253. break;
  254. case 6:
  255. [trainMsgLabs addObject:lab];
  256. break;
  257. default:
  258. break;
  259. }
  260. }else if (i==1){
  261. lab.textColor = defGreen;
  262. switch (j) {
  263. case 1:
  264. [trainMsgLabs addObject:lab];
  265. break;
  266. case 2:
  267. [trainMsgLabs addObject:lab];
  268. break;
  269. case 3:
  270. [trainMsgLabs addObject:lab];
  271. break;
  272. case 4:
  273. [trainMsgLabs addObject:lab];
  274. break;
  275. case 5:
  276. lab.textColor = kTitleColor;
  277. lab.text = @"有效时长";
  278. break;
  279. case 6:
  280. lab.textColor = [UIColor cyanColor];
  281. [trainMsgLabs addObject:lab];
  282. break;
  283. default:
  284. break;
  285. }
  286. }else if (i==2){
  287. lab.textColor = [UIColor redColor];
  288. switch (j) {
  289. case 1:
  290. [trainMsgLabs addObject:lab];
  291. break;
  292. case 2:
  293. [trainMsgLabs addObject:lab];
  294. break;
  295. case 3:
  296. [trainMsgLabs addObject:lab];
  297. break;
  298. case 4:
  299. [trainMsgLabs addObject:lab];
  300. break;
  301. case 5:
  302. lab.textColor = kTitleColor;
  303. lab.text = @"无效时长";
  304. break;
  305. case 6:
  306. [trainMsgLabs addObject:lab];
  307. break;
  308. default:
  309. break;
  310. }
  311. }
  312. else if (i==3){
  313. lab.textColor = kTitleColor;
  314. switch (j) {
  315. case 1:
  316. [trainMsgLabs addObject:lab];
  317. break;
  318. case 2:
  319. [trainMsgLabs addObject:lab];
  320. break;
  321. case 3:
  322. [trainMsgLabs addObject:lab];
  323. break;
  324. case 4:
  325. [trainMsgLabs addObject:lab];
  326. break;
  327. case 5:
  328. lab.text = @"待审核时长";
  329. break;
  330. case 6:
  331. lab.textColor = defGreen;
  332. [trainMsgLabs addObject:lab];
  333. break;
  334. default:
  335. break;
  336. }
  337. }
  338. }
  339. }
  340. //line
  341. CGFloat lineW = 1;
  342. for (int i=0; i<9; i++) {
  343. //垂直
  344. if (i<5) {
  345. UIView *lineVer3 = [[UIView alloc]initWithFrame:CGRectMake(w*i, y, lineW, h*5)];
  346. lineVer3.backgroundColor = [UIColor lightGrayColor];
  347. [mainScrV addSubview:lineVer3];
  348. UIView *lineVer4 = [[UIView alloc]initWithFrame:CGRectMake(w*i, y+h*5+bd, lineW, h*2)];
  349. lineVer4.backgroundColor = [UIColor lightGrayColor];
  350. [mainScrV addSubview:lineVer4];
  351. }
  352. //水平
  353. UIView *lineHor = [[UIView alloc]initWithFrame:CGRectMake(0, y+h*i, kSize.width, lineW)];
  354. lineHor.backgroundColor = [UIColor lightGrayColor];
  355. if (i>=6) {
  356. lineHor.frame = CGRectMake(0, y+h*(i-1)+bd, kSize.width, lineW);
  357. }
  358. [mainScrV addSubview:lineHor];
  359. }
  360. x = 10;
  361. y += 7*h+bd+lineW;
  362. w = kSize.width - x - 15;
  363. h = 50;
  364. trainDetails = [[UILabel alloc]setxywh];
  365. trainDetails.backgroundColor = backGroundColor;
  366. [trainDetails setText:@"" Font:Font17 TextColor:contentTextColor Alignment:NSTextAlignmentLeft];
  367. trainDetails.numberOfLines = 0;
  368. trainDetails.contentMode = UIViewContentModeCenter;
  369. trainDetails.adjustsFontSizeToFitWidth = YES;
  370. [mainScrV addSubview:trainDetails];
  371. //培训照片
  372. x = 10;
  373. y += h;
  374. w = kSize.width;
  375. h = 50;
  376. UILabel *trainPhotoeLab = [[UILabel alloc]setxywh];
  377. [trainPhotoeLab setText:@"培训照片" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
  378. [mainScrV addSubview:trainPhotoeLab];
  379. w = 110;
  380. h = 35;
  381. x = kSize.width - w - 15;
  382. y += (trainPhotoeLab.height-h)/2;
  383. checkTrainPhotoBtn = [UIButton buttonWithType:UIButtonTypeSystem];
  384. checkTrainPhotoBtn.layer.masksToBounds = YES;
  385. checkTrainPhotoBtn.layer.cornerRadius = 5;
  386. checkTrainPhotoBtn.frame = CGRectMake(x, y, w, h);
  387. [checkTrainPhotoBtn setTitle:@"查看更多照片" textColor:[UIColor darkGrayColor] font:FontTitle fotState:UIControlStateNormal];
  388. [checkTrainPhotoBtn addTarget:self action:@selector(checkTrainPhotoBtnClick) forControlEvents:UIControlEventTouchUpInside];
  389. checkTrainPhotoBtn.backgroundColor = [UIColor lightGrayColor];
  390. [mainScrV addSubview:checkTrainPhotoBtn];
  391. x = 0;
  392. y += (trainPhotoeLab.height-h)/2+h;
  393. w = kSize.width;
  394. h = 3;
  395. [trainPhotoeLab addViewWithRect:CGRectMake(x, y, w, h) Color:defGreen];
  396. [mainScrV setContentSize:CGSizeMake(0, y+h+20+kSafeAreaBottomHeight)];
  397. }
  398. -(void)customNavigationBar{
  399. UIBarButtonItem* backBbi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"question_pre_checked_icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(goBackByNavigation)];
  400. [backBbi setTintColor:defGreen];
  401. [self.navigationItem setLeftBarButtonItem:backBbi];
  402. self.navigationController.navigationBar.translucent = NO;
  403. }
  404. -(void)goBackByNavigation{
  405. if (self.navigationController.presentingViewController) {
  406. [self.navigationController dismissViewControllerAnimated:YES completion:nil];
  407. }else{
  408. [self.navigationController popViewControllerAnimated:YES];
  409. }
  410. }
  411. - (void)checkMinRecordBtnClick{
  412. EleMinRecordListVC *vc = [[EleMinRecordListVC alloc]init];
  413. vc.stuID = defUser.userDict[@"outId"];
  414. vc.classId = gatherTrainDic[@"classId"];
  415. [self navPushHideTabbarToVC:vc];
  416. }
  417. - (void)checkTrainPhotoBtnClick{
  418. NSArray *dataImgs = bigCarDic[@"picList"];
  419. if (dataImgs.count == 0) {
  420. return;
  421. }
  422. TileViewController *vc = [[TileViewController alloc]initWithImageNames:dataImgs];
  423. [self navPushHideTabbarToVC:vc];
  424. }
  425. - (void)nextWithCurrentStatu:(NSString *)statu{
  426. myDelegate.dcTrainType = statu;
  427. [self getGatherTrainDic];//这一步可以拿到登录接口返回并存储的claaid等课时相关信息
  428. //这里做补传学时的操作,如果不继续计时,就补传学时
  429. if (![statu isEqualToString:@"0"]) {
  430. classId = gatherTrainDic[@"classId"];
  431. NSArray *minuteTrainArray = [DB_Helper quearyTrainWithClassId:classId type:bigCarTableName];
  432. if (minuteTrainArray.count != 0) {
  433. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:@"提醒" message:@"检测到本地有未上传学时,是否现在补传学时" preferredStyle:UIAlertControllerStyleAlert];
  434. [alertFind addAction:[UIAlertAction actionWithTitle:@"否" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  435. }]];
  436. [alertFind addAction:[UIAlertAction actionWithTitle:@"是" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  437. [self uploadAppTrainPlWithSignOut:YES];
  438. }]];
  439. [self presentViewController:alertFind animated:true completion:nil];
  440. return;
  441. }
  442. }
  443. //获取到状态
  444. /*
  445. Type 定义 0 成功获取终端信息
  446. 1 学员还未在终端签到
  447. 2 学员签到的记录没有绑定终端
  448. 3 学员签到记录绑定的终端没有找到终端
  449. 4 学员签到记录的终端不在线
  450. 5 连接的终端非车载计时终端
  451. 6 未找到带教教练
  452. */
  453. if ([statu isEqualToString:@"0"]) {//成功获取终端信息 终端签到过就有
  454. //UI
  455. NSString *coach = bigCarDic[@"CoachName"];
  456. if (coach && coach.length > 0) {
  457. coachLab.text = [NSString stringWithFormat:@"带教教练:%@",coach];
  458. }
  459. carNum.text = bigCarDic[@"TDI_TRAIN_CAR_LICNUM"];
  460. [self refreshTrainPhotos];
  461. [self getStudentTrainInfos];//获取训练信息
  462. peripheralName = bigCarDic[@"TDI_TRAIN_CAR_LICNUM"];
  463. classId = bigCarDic[@"ClassId"];
  464. [gatherTrainDic setValue:bigCarDic[@"ClassId"] forKey:@"classId"];
  465. //保存至本地 可以用于断线重连
  466. [gatherTrainDic setValue:@"0" forKey:@"isOver"];
  467. [self saveGatherTrainDic];
  468. [self searchBlueTooth];//搜索蓝牙进行连接
  469. }else if([statu isEqualToString:@"1"]){//学员还未在终端器签到 5分钟检测到被签退
  470. if (timer) {
  471. [self uploadAppTrainPlWithSignOut:YES];
  472. [self refreshTrainPhotos];
  473. [self getStudentTrainInfos];
  474. return;
  475. }
  476. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:@"提醒" message:@"当前暂未检测到终端签到信息;如需计时,请在终端签到" preferredStyle:UIAlertControllerStyleAlert];
  477. [alertFind addAction:[UIAlertAction actionWithTitle:@"我知道了" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  478. }]];
  479. [alertFind addAction:[UIAlertAction actionWithTitle:@"终端已签到" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  480. [self getCurrentState];
  481. }]];
  482. [self presentViewController:alertFind animated:true completion:nil];
  483. }else if ([statu isEqualToString:@"2"]) {//学员签到的记录没有绑定终端
  484. showMsgByAlert(self, @"学员签到的记录没有绑定终端");
  485. }else if ([statu isEqualToString:@"3"]) {//学员签到记录绑定的终端没有找到终端
  486. showMsgByAlert(self, @"学员签到记录绑定的终端没有找到终端");
  487. }else if ([statu isEqualToString:@"4"]) {//学员签到记录的终端不在线
  488. showMsgByAlert(self, @"学员签到记录的终端不在线");
  489. }else if ([statu isEqualToString:@"5"]) {//连接的终端非车载计时终端
  490. showMsgByAlert(self, @"连接的终端非车载计时终端");
  491. }else if ([statu isEqualToString:@"6"]) {//未找到带教教练
  492. showMsgByAlert(self, @"未找到带教教练");
  493. }
  494. }
  495. #pragma mark - 添加本地通知
  496. -(void)addLocalNotificationWithAudio:(NSString *)audioName{
  497. //定义本地通知对象
  498. UILocalNotification *notification = [[UILocalNotification alloc]init];
  499. //设置调用时间
  500. notification.fireDate = [NSDate date];
  501. //设置通知属性
  502. NSString *bodyString = @"优易学车提醒您";
  503. if ([audioName isEqualToString:@"dc_blueToothDisconnect.mp3"]) {
  504. bodyString = @"车宰设备已断开,计时停止";
  505. }else if ([audioName isEqualToString:@"dc_blueToothConnect.mp3"]) {
  506. bodyString = @"车宰设备连接成功,恢复计时";
  507. }
  508. notification.alertBody = bodyString; //通知主体
  509. notification.applicationIconBadgeNumber = 1;//应用程序图标右上角显示的消息数
  510. notification.alertAction = @"打开应用"; //待机界面的滑动动作提示
  511. notification.soundName = audioName;//收到通知时播放的声音,默认消息声音
  512. // 通知参数
  513. NSDictionary *userDict = [NSDictionary dictionaryWithObjectsAndKeys:@"nothing",@"BigTruckTrainVC", nil];
  514. notification.userInfo = userDict;
  515. //调用通知
  516. [[UIApplication sharedApplication] scheduleLocalNotification:notification];
  517. }
  518. #pragma mark - 本地数据读取
  519. - (void)saveGatherTrainDic
  520. {
  521. NSString *filePath = [Tools getPathWithFileName:@"BigCarTrainDic.plist"];
  522. [gatherTrainDic writeToFile:filePath atomically:YES];
  523. }
  524. - (void)getGatherTrainDic
  525. {
  526. NSString *filePath = [Tools getPathWithFileName:@"BigCarTrainDic.plist"];
  527. if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
  528. gatherTrainDic = [NSMutableDictionary dictionaryWithContentsOfFile:filePath];
  529. }
  530. }
  531. #pragma mark gps定位相关
  532. -(void)setGPSLocationService{
  533. //实例化manager
  534. locationManager=[[CLLocationManager alloc]init];
  535. //设置代理
  536. locationManager.delegate=self;
  537. //设置定位精度
  538. //定位要求的精度越高、属性distanceFilter的值越小,应用程序的耗电量就越大。
  539. locationManager.desiredAccuracy=kCLLocationAccuracyNearestTenMeters;
  540. //定位距离
  541. locationManager.distanceFilter=50; //这里定位只是为了使其后台运行
  542. //申请定位许可,iOS8以后特有
  543. /** 由于IOS8中定位的授权机制改变 需要进行手动授权
  544. * 获取授权认证,两个方法:
  545. * [self.locationManager requestWhenInUseAuthorization];
  546. * [self.locationManager requestAlwaysAuthorization];
  547. */
  548. if([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
  549. [locationManager requestAlwaysAuthorization];
  550. }
  551. if ([[UIDevice currentDevice].systemVersion floatValue] > 9)
  552. {
  553. /** iOS9新特性:将允许出现这种场景:同一app中多个location manager:一些只能在前台定位,另一些可在后台定位(并可随时禁止其后台定位)。 */
  554. [locationManager setAllowsBackgroundLocationUpdates:YES];
  555. }
  556. //开始定位
  557. [locationManager startUpdatingLocation];
  558. }
  559. - (void)locationManager:(CLLocationManager *)manager
  560. didFailWithError:(NSError *)error{
  561. /*
  562. kCLErrorDenied,//访问位置或范围已被用户拒绝
  563. kCLErrorNetwork,//一般,与网络相关的错误
  564. */
  565. NSLog(@"位置访问失败");
  566. UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请在iPhone的“设置”-“隐私”-“定位服务”功能中,找到“优易学车”打开位置访问权限" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
  567. [alert show];
  568. [locationManager stopUpdatingLocation];
  569. }
  570. //- (void)locationManager:(CLLocationManager *)manager
  571. // didUpdateToLocation:(CLLocation *)newLocation
  572. // fromLocation:(CLLocation *)oldLocation
  573. //{
  574. // //打印出经度和纬度
  575. // CLLocationCoordinate2D coordinate = newLocation.coordinate;
  576. // NSDictionary *testdic =BMKConvertBaiduCoorFrom(coordinate,BMK_COORDTYPE_GPS);//转换GPS坐标至百度坐标(加密后的坐标)
  577. // //解密加密后的坐标字典
  578. // CLLocationCoordinate2D baiduCoor = BMKCoorDictionaryDecode(testdic);//转换后的百度坐标
  579. // myCoordinate = baiduCoor;
  580. //
  581. // [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  582. // NSString *strDate = [dateFormatter stringFromDate:newLocation.timestamp];
  583. //
  584. // //暂时未用到
  585. // gpsDic = [NSMutableDictionary dictionaryWithDictionary:@{
  586. // @"latitude":[NSString stringWithFormat:@"%f",baiduCoor.latitude],
  587. // @"longitude":[NSString stringWithFormat:@"%f",baiduCoor.longitude],
  588. // @"altitude":[NSString stringWithFormat:@"%.2f",newLocation.altitude],
  589. // @"timestamp":strDate,
  590. // }];
  591. //}
  592. - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(nonnull NSArray<CLLocation *> *)locations {
  593. CLLocation *loctaion = [locations firstObject];
  594. CLLocationCoordinate2D coordinate = loctaion.coordinate;
  595. myCoordinate = BMKCoordTrans(coordinate, BMK_COORDTYPE_GPS, BMK_COORDTYPE_BD09LL);//转换GPS坐标至百度坐标(加密后的坐标)
  596. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  597. NSString *strDate = [dateFormatter stringFromDate:loctaion.timestamp];
  598. //暂时未用到
  599. gpsDic = [NSMutableDictionary dictionaryWithDictionary:@{
  600. @"latitude":[NSString stringWithFormat:@"%f",myCoordinate.latitude],
  601. @"longitude":[NSString stringWithFormat:@"%f",myCoordinate.longitude],
  602. @"altitude":[NSString stringWithFormat:@"%.2f",loctaion.altitude],
  603. @"timestamp":strDate,
  604. }];
  605. }
  606. #pragma mark 蓝牙相关
  607. - (void)addBlueToothLabelWithContent:(NSString *)string mp3:(NSString *)audioStr{
  608. if (!self.blueToothLabel.superview) {
  609. [[UIApplication sharedApplication].keyWindow addSubview:self.blueToothLabel];
  610. }
  611. self.blueToothLabel.text = string;
  612. if(audioStr){
  613. if (myDelegate.isBackgroundTask) {
  614. [self addLocalNotificationWithAudio:audioStr];
  615. }else {
  616. [Tools playAudioWithString:string];
  617. }
  618. }
  619. }
  620. - (void)removeBlueToothLabel {
  621. if (_blueToothLabel) {
  622. [_blueToothLabel removeFromSuperview];
  623. }
  624. }
  625. -(UIView *)blueToothLabel {
  626. if (!_blueToothLabel) {
  627. _blueToothLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, (kSize.height - 90)/2.0, kSize.width - 60, 80)];
  628. _blueToothLabel.numberOfLines = 0;
  629. _blueToothLabel.backgroundColor = backGroundColor;
  630. [_blueToothLabel setBoardWid:5 Color:contentTextColor];
  631. [_blueToothLabel setText:@"" Font:24 TextColor:kTitleColor Alignment:NSTextAlignmentCenter];
  632. }
  633. return _blueToothLabel;
  634. }
  635. - (void)closeBlueTooth {
  636. if (peripheralName.length > 0) {
  637. //断开连接
  638. if (self.peripheral) {
  639. [self.cbcManager cancelPeripheralConnection:self.peripheral];
  640. }
  641. self.peripheral.delegate = nil;
  642. self.peripheral = nil;
  643. self.writeCharacteristic = nil;
  644. self.readCharacteristic = nil;
  645. self.cbcManager = nil;
  646. }
  647. }
  648. - (void)searchBlueTooth {
  649. blueToothOrder = @"";
  650. if (!_cbcManager) {
  651. _cbcManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
  652. }
  653. }
  654. //只要中心管理者初始化 就会触发此代理方法 判断手机蓝牙状态
  655. - (void)centralManagerDidUpdateState:(CBCentralManager *)central
  656. {
  657. switch (central.state) {
  658. case 0:
  659. //状态未知
  660. //NSLog(@"CBCentralManagerStateUnknown");
  661. break;
  662. case 1:
  663. //连接断开 即将重置
  664. //NSLog(@"CBCentralManagerStateResetting");
  665. break;
  666. case 2:
  667. //该平台不支持蓝牙
  668. //NSLog(@"CBCentralManagerStateUnsupported");
  669. break;
  670. case 3:
  671. //未授权蓝牙使用 hovertree.com
  672. //NSLog(@"CBCentralManagerStateUnauthorized");
  673. {
  674. [self removeBlueToothLabel];
  675. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"请在“设置”中打开蓝牙访问权限" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
  676. [alert show];
  677. }
  678. break;
  679. case 4:
  680. {
  681. //蓝牙未开启
  682. //NSLog(@"CBCentralManagerStatePoweredOff");
  683. if (peripheralName.length > 0) {
  684. showMsgByAlert(self, @"请打开手机蓝牙");
  685. [Tools playAudioWithString:@"请打开手机蓝牙"];
  686. }
  687. }
  688. break;
  689. case 5:
  690. {
  691. //蓝牙已开启
  692. //NSLog(@"CBCentralManagerStatePoweredOn");
  693. if (peripheralName.length < 1) {
  694. return;
  695. }
  696. // 搜索外设
  697. if (self.peripheral) {
  698. return;
  699. }
  700. // 搜索成功之后,会调用找到外设的代理方法
  701. [self addBlueToothLabelWithContent:[NSString stringWithFormat:@"正在连接终端设备 %@ 请稍候",peripheralName] mp3:nil];
  702. [self.cbcManager scanForPeripheralsWithServices:nil // 通过某些服务筛选外设
  703. options:nil]; // dict,条件
  704. }
  705. break;
  706. default:
  707. break;
  708. }
  709. }
  710. // 发现外设后调用的方法
  711. - (void)centralManager:(CBCentralManager *)central // 中心管理者
  712. didDiscoverPeripheral:(CBPeripheral *)peripheral // 外设
  713. advertisementData:(NSDictionary *)advertisementData // 外设携带的数据
  714. RSSI:(NSNumber *)RSSI // 外设发出的蓝牙信号强度
  715. {
  716. NSLog(@"搜索到的外设----><>%@----><>%@",peripheral.name,peripheralName);
  717. //如果蓝牙名称和二维码中的一致 就可以连接了 最好能关闭蓝牙的扫描
  718. if ([peripheral.name isEqualToString:peripheralName]) {
  719. self.peripheral = peripheral;
  720. [self.cbcManager stopScan];
  721. [_cbcManager connectPeripheral:self.peripheral options:nil];
  722. }
  723. }
  724. // 中心管理者连接外设成功
  725. - (void)centralManager:(CBCentralManager *)central // 中心管理者
  726. didConnectPeripheral:(CBPeripheral *)peripheral // 外设
  727. {
  728. NSLog(@"%s, line = %d, %@=连接成功", __FUNCTION__, __LINE__, peripheral.name);
  729. _blueToothLabel.text = @"连接成功";
  730. dispatch_time_t zz = dispatch_time(DISPATCH_TIME_NOW, 1.5 * NSEC_PER_SEC);
  731. dispatch_after(zz, dispatch_get_main_queue(), ^{
  732. [self removeBlueToothLabel];
  733. });
  734. // 连接成功之后,可以进行服务和特征的发现
  735. // 设置外设的代理
  736. self.peripheral.delegate = self;
  737. // 外设发现服务,传nil代表不过滤
  738. [self.peripheral discoverServices:@[ [CBUUID UUIDWithString:BServiceUUID] ]];
  739. isConnectBlueTooth = YES;
  740. disconnectSeconds = 0;
  741. //因为断开重连也需要验证 所以就不。。。
  742. // if (myDelegate.isBackgroundTask) {
  743. // [self addLocalNotificationWithAudio:@"dc_blueToothConnect.mp3"];
  744. // }else {
  745. // [Tools playAudioWithString:@"已成功连接车宰设备"];
  746. // }
  747. }
  748. // 外设连接失败
  749. - (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error
  750. {
  751. isConnectBlueTooth = NO;
  752. NSLog(@"%s, line = %d, %@=连接失败", __FUNCTION__, __LINE__, peripheral.name);
  753. [self addBlueToothLabelWithContent:@"终端设备连接失败!正在尝试重新连接" mp3:nil];
  754. if (self.peripheral) {
  755. [_cbcManager connectPeripheral:self.peripheral options:nil];
  756. }
  757. }
  758. // 丢失连接
  759. - (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error
  760. {
  761. isConnectBlueTooth = NO;
  762. NSLog(@"%s, line = %d, %@=断开连接", __FUNCTION__, __LINE__, peripheral.name);
  763. if (self.cbcManager && self.peripheral) {
  764. [self.cbcManager connectPeripheral:self.peripheral options:nil];
  765. //断开链接后在timerun里面每5s发起一次蓝牙连接请求。 并且seconds不自增
  766. }
  767. if (timer) {
  768. ShowMsg(@"车载设备已断开,计时停止");
  769. topRight.selected = YES;
  770. topRight.alpha = 1.0;
  771. if (myDelegate.isBackgroundTask) {
  772. [self addLocalNotificationWithAudio:@"dc_blueToothDisconnect.mp3"];
  773. }else {
  774. [Tools playAudioWithString:@"车宰设备已断开,计时停止"];
  775. }
  776. }
  777. }
  778. //查找服务的所有特征
  779. - (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error {
  780. if (error)
  781. {
  782. NSLog(@"Discovered services for %@ with error: %@", peripheral.name, [error localizedDescription]);
  783. [self addBlueToothLabelWithContent:@"蓝牙服务搜索失败" mp3:nil];
  784. return;
  785. }
  786. //NSLog(@"services---><>%@",peripheral.services);
  787. //服务并不是我们的目标,也没有实际意义。我们需要用的是服务下的特征,查询(每一个服务下的若干)特征
  788. for (CBService *service in peripheral.services)
  789. {
  790. NSLog(@"Service found with UUID: %@", service.UUID);
  791. // Discovers the characteristics for a given service
  792. if ([service.UUID isEqual:[CBUUID UUIDWithString:BServiceUUID]]) {
  793. //搜索特性
  794. [self.peripheral discoverCharacteristics:nil forService:service];
  795. }
  796. }
  797. }
  798. // 发现外设服务里的特征的时候调用的代理方法(这个是比较重要的方法,你在这里可以通过事先知道UUID找到你需要的特征,订阅特征,或者这里写入数据给特征也可以)
  799. - (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error
  800. {
  801. if (error) {
  802. NSLog(@"搜索特性失败 characteristic: %@", [error localizedDescription]);
  803. [self addBlueToothLabelWithContent:@"蓝牙服务特征搜索失败" mp3:nil];
  804. return;
  805. }
  806. /* 这里经过测试 读写全用UUID为FFE1的特征 这样收到的蓝牙回复 没有很多的多余的数据
  807. */
  808. for (CBCharacteristic *cha in service.characteristics) {
  809. if ([cha.UUID isEqual:[CBUUID UUIDWithString:BCharacteristicUUID_reade]]) {
  810. // NSLog(@"读取特征-->>>%@",cha);
  811. self.readCharacteristic = cha;
  812. [peripheral setNotifyValue:YES forCharacteristic:cha];
  813. // [peripheral readValueForCharacteristic:cha];
  814. /*
  815. 最后还有一个重要的补充,当我们已经找到了我们感兴趣的characteristic后,他的value并不一定通过1方法或者2方法就可以接收的,就算可以接收,有时候只能用1,有时候只能用2。
  816. 这牵扯到characteristic的一个property
  817. 当为read(0x02)的时候,我们用1方法可以查看,用2就会出错。当为notify(0x10)的时候我们就得用2方法。其他就不说明了,比如write就只能写value······
  818. typedef enum {
  819. CBCharacteristicPropertyBroadcast = 0x01,
  820. CBCharacteristicPropertyRead = 0x02,
  821. CBCharacteristicPropertyWriteWithoutResponse = 0x04,
  822. CBCharacteristicPropertyWrite = 0x08,
  823. CBCharacteristicPropertyNotify = 0x10,
  824. CBCharacteristicPropertyIndicate = 0x20,
  825. CBCharacteristicPropertyAuthenticatedSignedWrites = 0x40,
  826. CBCharacteristicPropertyExtendedProperties = 0x80,
  827. CBCharacteristicPropertyNotifyEncryptionRequired = 0x100,
  828. CBCharacteristicPropertyIndicateEncryptionRequired = 0x200,
  829. } CBCharacteristicProperties;
  830. 所以当我们想查看value的时候,先了解一下这个characteristic的property,看是不是能让我们读的。怎么查看?找BLE外设的设备厂商或者查看外设的说明书。
  831. 推荐将value经常变化的characteristic的property设为notify
  832. */
  833. }
  834. if ([cha.UUID isEqual:[CBUUID UUIDWithString:BCharacteristicUUID_write]]) {
  835. // NSLog(@"写入特征-->>>%@",cha);//0x04对应的是CBCharacteristicPropertyWriteWithoutResponse || 0x0A对应的是CBCharacteristicPropertyNotify
  836. self.writeCharacteristic = cha;
  837. //重新连接/开始连接都需要发这个验证
  838. blueToothOrder = [NSString stringWithFormat:@"%@%@",RequestConnectOrder,defUser.userDict[@"stuNum"]];
  839. [self sendBlueToothOrder];
  840. }
  841. }
  842. }
  843. - (void)peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic:(nonnull CBCharacteristic *)characteristic error:(nullable NSError *)error {
  844. if (error) {
  845. NSLog(@"Error changing notification state: %@", error.localizedDescription);
  846. // [self addBlueToothLabelWithContent:@"蓝牙服务特征状态异常" mp3:nil];
  847. return;
  848. }
  849. // Exits if it's not the transfer characteristic
  850. if (![characteristic.UUID isEqual:[CBUUID UUIDWithString:BCharacteristicUUID_reade]]) {
  851. return;
  852. }
  853. // Notification has started
  854. if (characteristic.isNotifying) {
  855. NSLog(@"Notification began on %@", characteristic);
  856. NSLog(@"%@",characteristic.value);
  857. NSLog(@"%@",[[NSString alloc]initWithData:characteristic.value encoding:NSUTF8StringEncoding]);
  858. [peripheral readValueForCharacteristic:characteristic];
  859. } else { // Notification has stopped
  860. NSLog(@"Notification stopped on %@. Disconnecting", characteristic);
  861. }
  862. }
  863. // 更新特征的value的时候会调用 (凡是从蓝牙传过来的数据都要经过这个回调,简单的说这个方法就是你拿数据的唯一方法)
  864. - (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
  865. {
  866. if ([characteristic isEqual:self.readCharacteristic] ) {
  867. NSString *hexString = [Tools convertDataToHexStr:characteristic.value];
  868. NSLog(@"hexString---><>%@",hexString);
  869. if ([hexString containsString:@"be0204"]) {
  870. hasReply = YES;
  871. NSString *result = [hexString substringFromIndex:hexString.length-2];
  872. if ([result isEqualToString:@"00"]) {
  873. //连接成功,可以开始培训
  874. if (timer) {//表示是蓝牙断开重连
  875. topRight.selected = NO;
  876. if (myDelegate.isBackgroundTask) {
  877. [self addLocalNotificationWithAudio:@"dc_blueToothConnect.mp3"];
  878. }else {
  879. [Tools playAudioWithString:@"车宰设备连接成功,恢复计时"];
  880. }
  881. }else{
  882. [Tools playAudioWithString:@"连接成功,开始计时"];
  883. [self beginTimer];
  884. }
  885. }else if ([result isEqualToString:@"01"]){
  886. showMsgByAlert(self, @"非当前训练学员,连接失败");
  887. [Tools playAudioWithString:@"非当前训练学员,连接失败"];
  888. [self closeBlueTooth];
  889. }
  890. return;
  891. }
  892. if ([hexString containsString:@"be0501"]) {//心跳回应
  893. blueToothOrder = HeartbeatOrder;
  894. [self sendBlueToothOrder];
  895. }
  896. if ([hexString containsString:@"be0103"]) {//签退通知
  897. //这个回复没意义。终端签退即签退
  898. // blueToothOrder = QuitOrder;
  899. // [self sendBlueToothOrder];
  900. if (timer) {
  901. [timer invalidate];
  902. timer = nil;
  903. }
  904. [self uploadAppTrainPlWithSignOut:YES];
  905. }
  906. }
  907. }
  908. -(void)peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(nonnull CBCharacteristic *)characteristic error:(nullable NSError *)error{
  909. if (error) {
  910. NSLog(@"写入数据失败:%@",error);
  911. [self addBlueToothLabelWithContent:@"蓝牙连接异常,指令发送失败" mp3:nil];
  912. }else{
  913. NSLog(@"写入数据成功-->: %@",blueToothOrder);
  914. }
  915. }
  916. #pragma mark - 蓝牙写入数据
  917. - (void)sendBlueToothOrder{
  918. dataIsLack = NO;
  919. lastData = nil;
  920. hasReply = NO;
  921. if (blueToothOrder && blueToothOrder.length != 0) {
  922. [self.peripheral writeValue:[Tools convertHexStrToData:blueToothOrder] forCharacteristic:self.writeCharacteristic type:CBCharacteristicWriteWithResponse];
  923. }
  924. if ([blueToothOrder containsString:RequestConnectOrder]) {//可能刚开始连上的时候 接受不到消息
  925. dispatch_time_t zz = dispatch_time(DISPATCH_TIME_NOW, 2* NSEC_PER_SEC);
  926. dispatch_after(zz, dispatch_get_main_queue(), ^{
  927. if (hasReply == NO) {
  928. [self sendBlueToothOrder];
  929. }
  930. });
  931. }
  932. }
  933. #pragma mark 教学信息更新
  934. -(void)reloadDetailLabWithDic:(NSDictionary *)dic{
  935. //更新UI展示内容
  936. int i=0;
  937. for (UILabel *lab in trainMsgLabs) {
  938. switch (i) {//按从上往下 从左往右 1+5+5
  939. case 0:
  940. lab.text = [self getTimeByMinString:dic[@"totalTime"]];
  941. break;
  942. case 1:
  943. lab.text = [self getTimeByMinString:dic[@"ONE"]];
  944. break;
  945. case 2:
  946. lab.text = [self getTimeByMinString:dic[@"TWO"]];
  947. break;
  948. case 3:
  949. lab.text = [self getTimeByMinString:dic[@"THREE"]];
  950. break;
  951. case 4:
  952. lab.text = [self getTimeByMinString:dic[@"FOUR"]];
  953. break;
  954. case 5:
  955. lab.text = [self getTimeByMinString:dic[@"vaildTime"]];
  956. break;
  957. case 6:
  958. {
  959. NSArray *arr = [self getStrAndColorByStatus:dic[@"ONESTATUS"]];
  960. lab.text = arr[1];
  961. lab.textColor = arr[0];
  962. }
  963. break;
  964. case 7:
  965. {
  966. NSArray *arr = [self getStrAndColorByStatus:dic[@"TWOSTATUS"]];
  967. lab.text = arr[1];
  968. lab.textColor = arr[0];
  969. }
  970. break;
  971. case 8:
  972. {
  973. NSArray *arr = [self getStrAndColorByStatus:dic[@"THREESTATUS"]];
  974. lab.text = arr[1];
  975. lab.textColor = arr[0];
  976. }
  977. break;
  978. case 9:
  979. {
  980. NSArray *arr = [self getStrAndColorByStatus:dic[@"FOURSTATUS"]];
  981. lab.text = arr[1];
  982. lab.textColor = arr[0];
  983. }
  984. break;
  985. case 10:
  986. lab.text = [self getTimeByMinString:dic[@"noVaildTime"]];
  987. break;
  988. case 11:
  989. {
  990. NSArray *arr = [self getSureStrAndColorByStatus:dic[@"CHECKONE"]];
  991. lab.text = arr[1];
  992. lab.textColor = arr[0];
  993. }
  994. break;
  995. case 12:
  996. {
  997. NSArray *arr = [self getSureStrAndColorByStatus:dic[@"CHECKTWO"]];
  998. lab.text = arr[1];
  999. lab.textColor = arr[0];
  1000. }
  1001. break;
  1002. case 13:
  1003. {
  1004. NSArray *arr = [self getSureStrAndColorByStatus:dic[@"CHECKTHREE"]];
  1005. lab.text = arr[1];
  1006. lab.textColor = arr[0];
  1007. }
  1008. break;
  1009. case 14:
  1010. {
  1011. NSArray *arr = [self getSureStrAndColorByStatus:dic[@"CHECKFOUR"]];
  1012. lab.text = arr[1];
  1013. lab.textColor = arr[0];
  1014. }
  1015. break;
  1016. case 15:
  1017. lab.text = [self getTimeByMinString:dic[@"notAuditTime"]];
  1018. break;
  1019. default:
  1020. break;
  1021. }
  1022. i++;
  1023. }
  1024. NSInteger totalTime = [[NSString stringWithFormat:@"%@",dic[@"totalTime"]] integerValue];
  1025. trainDetails.text = [NSString stringWithFormat:@"当前培训过程中,车辆平均速度为%.2fKm/h,行驶总里程为%.2fKm,有效学时占比为%.1f%%",[dic[@"avgSpeed"] floatValue],[dic[@"totalMile"] floatValue]/1000.0, totalTime==0 ? 0 : [dic[@"vaildTime"] floatValue]/[dic[@"totalTime"] floatValue]*100];
  1026. }
  1027. -(NSString *)getTimeByMinString:(NSString *)minStr{
  1028. NSInteger min = [minStr integerValue];
  1029. NSInteger h = min/60;
  1030. NSInteger m = min%60;
  1031. if (h != 0) {
  1032. return [NSString stringWithFormat:@"%ld小时%ld分钟",h,m];
  1033. }
  1034. return [NSString stringWithFormat:@"%ld分钟",m];
  1035. }
  1036. -(NSArray *)getStrAndColorByStatus:(NSString *)status{
  1037. NSString *stateString = status;
  1038. UIColor *color = [UIColor blackColor];
  1039. switch ([stateString intValue]) {
  1040. case 0:
  1041. stateString = @"不允许送审";
  1042. color = [UIColor redColor];
  1043. break;
  1044. case 1:
  1045. stateString = @"允许送审";
  1046. color = contentTextColor;
  1047. break;
  1048. case 2:
  1049. stateString = @"审核通过";
  1050. color = contentTextColor;
  1051. break;
  1052. case 3:
  1053. stateString = @"退回";
  1054. color = [UIColor redColor];
  1055. break;
  1056. case 4:
  1057. stateString = @"待审核";
  1058. color = [UIColor darkGrayColor];
  1059. break;
  1060. default:
  1061. stateString = @"<未知>";
  1062. color = [UIColor lightTextColor];
  1063. break;
  1064. }
  1065. return @[color,stateString];
  1066. }
  1067. -(NSArray *)getSureStrAndColorByStatus:(NSString *)status{
  1068. NSString *stateString = status;
  1069. UIColor *color = [UIColor blackColor];
  1070. switch ([stateString intValue]) {
  1071. case 0:
  1072. stateString = @"未确认";
  1073. color = contentTextColor;
  1074. break;
  1075. case 1:
  1076. stateString = @"已确认";
  1077. color = contentTextColor;
  1078. break;
  1079. default:
  1080. stateString = @"<未知>";
  1081. color = [UIColor lightTextColor];
  1082. break;
  1083. }
  1084. return @[color,stateString];
  1085. }
  1086. -(void)refreshTrainPhotos{
  1087. CGFloat tileView_H = 0;
  1088. if (tileView) {
  1089. [tileView removeFromSuperview];
  1090. [[self.childViewControllers lastObject] removeFromParentViewController];
  1091. tileView_H = tileView.height+30;//30 是下边留的空白
  1092. }
  1093. NSArray *dataImgs = bigCarDic[@"picList"];
  1094. if (dataImgs.count == 0) {
  1095. return;
  1096. }
  1097. [checkTrainPhotoBtn setTitle:@"查看更多照片" textColor:[UIColor whiteColor] font:FontTitle fotState:UIControlStateNormal];
  1098. checkTrainPhotoBtn.backgroundColor = defGreen;
  1099. NSArray *imgs = dataImgs.count>4?[dataImgs subarrayWithRange:NSMakeRange(0, 4)]:dataImgs;
  1100. TileViewController *vc = [[TileViewController alloc]initWithImageNames:imgs];
  1101. CGFloat h = kSize.width/2*3/4*(dataImgs.count/2>2 ? 2:dataImgs.count);
  1102. vc.view.frame = CGRectMake(0, mainScrV.contentSize.height-kSafeAreaBottomHeight-20-tileView_H, kSize.width, h);
  1103. [self addChildViewController:vc];
  1104. [mainScrV addSubview:vc.view];
  1105. tileView = vc.view;
  1106. [mainScrV setContentSize:CGSizeMake(0, mainScrV.contentSize.height+30+h-tileView_H)];//50=30+20
  1107. }
  1108. #pragma mark -开始计时
  1109. - (void)beginTimer {
  1110. [DB_Helper deleteAllTrainWithType:bigCarTableName];
  1111. [self getClassId];//获取classId
  1112. [gatherTrainDic setObject:classId forKey:@"classId"];
  1113. //classId
  1114. minuteTrainDic = [NSMutableDictionary dictionary];
  1115. [minuteTrainDic setValue:classId forKey:@"classId"];
  1116. seconds = 0;
  1117. disconnectSeconds = 0;
  1118. topRight.alpha = 1;
  1119. timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerRun) userInfo:nil repeats:YES];
  1120. [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];//处理UI交互阻塞计时
  1121. myDelegate.dcPeriodVC = self;
  1122. }
  1123. - (void)timerRun
  1124. {
  1125. NSLog(@"timerRuning");
  1126. statusLab.text = @"timerRuning";
  1127. if (!isConnectBlueTooth && peripheralName.length > 0) {//计时过程中蓝牙断开连接
  1128. disconnectSeconds ++;
  1129. //外设重连
  1130. if (disconnectSeconds%5 == 0) {
  1131. if (_cbcManager && self.peripheral) {
  1132. [_cbcManager connectPeripheral:self.peripheral options:nil];
  1133. NSLog(@"蓝牙断开每5s重新发起连接");
  1134. statusLab.text = @"蓝牙断开每5s重新发起连接";
  1135. }
  1136. }
  1137. //重新扫描间隔10 持续3
  1138. if (disconnectSeconds%10 == 0) {
  1139. if (!_cbcManager.isScanning) {
  1140. [self.cbcManager scanForPeripheralsWithServices:nil // 通过某些服务筛选外设
  1141. options:nil]; // dict,条件
  1142. }
  1143. }else if (disconnectSeconds%3 == 0) {
  1144. if (_cbcManager.isScanning) {
  1145. [self.cbcManager stopScan];
  1146. }
  1147. }
  1148. return;
  1149. }
  1150. topRight.alpha = seconds%2;
  1151. NSLog(@"timerRuning: %ld",seconds);
  1152. statusLab.text = [statusLab.text stringByAppendingString:[NSString stringWithFormat:@"%ld",seconds]];
  1153. //计时器
  1154. seconds++;
  1155. // NSLog(@"%d---->%@",seconds,blueToothOrder);
  1156. if (seconds%30 == 0) {
  1157. //这个点就当前时间
  1158. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  1159. NSString *dateString = [dateFormatter stringFromDate:[NSDate date]];
  1160. [minuteTrainDic setValue:classId forKey:@"classId"];
  1161. //{lng:121.595793,lat:41.961311,crTime:'2017-01-01 00:00:00'}
  1162. NSDictionary *dic = @{ @"lng":[NSString stringWithFormat:@"%f",myCoordinate.longitude],
  1163. @"lat":[NSString stringWithFormat:@"%f",myCoordinate.latitude],
  1164. @"crTime":dateString};
  1165. NSString *gpsStr = [self getJsonStringWithObj:dic];
  1166. [minuteTrainDic setValue:gpsStr forKey:@"gps"];
  1167. NSLog(@"存入的字典: %@",minuteTrainDic);
  1168. [DB_Helper saveTrainWithDic:minuteTrainDic type:bigCarTableName];
  1169. [self uploadAppTrainPlWithSignOut:NO];
  1170. }
  1171. if (seconds%300 == 0) {
  1172. [self getCurrentState];//刷新UI 里面有用到计时器状态判断是否是训练中 不会走开始训练的那些处理
  1173. }
  1174. }
  1175. - (void)getClassId
  1176. {
  1177. if (classId && classId.length > 0) {
  1178. return;
  1179. }
  1180. //将之前的学时全部清空
  1181. // [DB_Helper deleteAllTrainWithType:bigCarTableName];
  1182. // //classId
  1183. // NSTimeInterval timeInterval = [[NSDate date] timeIntervalSince1970]*1000;
  1184. //// NSString *timeString = [[[[NSString stringWithFormat:@"%f",timeInterval] substringFromIndex:1] componentsSeparatedByString:@"."] firstObject];
  1185. //// NSInteger redomNum = arc4random()%8999 + 1000;
  1186. //// classId = [NSString stringWithFormat:@"%d%@",(int)redomNum,timeString];
  1187. // NSString *timeString = [[[NSString stringWithFormat:@"%f",timeInterval] componentsSeparatedByString:@"."] lastObject];
  1188. // timeString = [timeString substringFromIndex:timeString.length-10];
  1189. // classId = timeString;
  1190. }
  1191. - (void)closeTimer{
  1192. [gatherTrainDic setValue:@"1" forKey:@"isOver"];
  1193. [gatherTrainDic removeObjectForKey:@"classId"];
  1194. [self saveGatherTrainDic];
  1195. [DB_Helper deleteAllTrainWithType:bigCarTableName];
  1196. [dataSourceArray removeAllObjects];
  1197. //先关闭定时器
  1198. if (timer.isValid) {
  1199. [timer invalidate];
  1200. timer = nil;
  1201. }
  1202. myDelegate.dcPeriodVC = nil;
  1203. myDelegate.dcTrainType = @"1";
  1204. [Tools playAudioWithString:@"本次计时结束"];
  1205. coachLab.text = @"带教教练:";
  1206. carNum.text = @"已签退";
  1207. topRight.alpha = 0;
  1208. }
  1209. #pragma mark - 转json字符串
  1210. - (NSString *)getJsonStringWithObj:(NSObject *)jsonObj{
  1211. NSError *error = nil;
  1212. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonObj
  1213. options:NSJSONWritingPrettyPrinted
  1214. error:&error];
  1215. NSString *jsonString = nil;
  1216. if ([jsonData length] != 0 && error == nil){
  1217. // 使用这个方法的返回,我们就可以得到想要的JSON串
  1218. jsonString = [[NSString alloc] initWithData:jsonData
  1219. encoding:NSUTF8StringEncoding];
  1220. }else{
  1221. ShowMsg(@"数据错误,请重试!");
  1222. }
  1223. return jsonString;
  1224. }
  1225. #pragma mark - 网络请求
  1226. //获取当前训练状态
  1227. -(void)getCurrentState
  1228. {
  1229. [MBProgressHUD showMessage:@"正在获取当前训练状态" toView:self.view];
  1230. //这个主要目的是为了更新本地学时编号等数据
  1231. [LoginViewController getCurrentStateWithCompleteBlock:^(NSDictionary *root) {
  1232. [MBProgressHUD hideHUDForView:self.view animated:NO];
  1233. if (!root) {
  1234. ShowMsg(@"请求失败");
  1235. return;
  1236. }
  1237. if ([root[@"code"] isEqualToString:@"0"]) {
  1238. bigCarDic = root[@"body"][@"bigCar"];
  1239. if (timer && [bigCarDic[@"TYPE"] isEqualToString:@"0"]) {//训练中
  1240. //刷新UI
  1241. [self refreshTrainPhotos];
  1242. [self getStudentTrainInfos];
  1243. return;
  1244. }
  1245. NSArray *arr = @[@"科目一",@"科目二",@"科目三",@"科目四"];
  1246. int subject = [[NSString stringWithFormat:@"%@",root[@"body"][@"subject"]] intValue];
  1247. if (subject <= 4) {
  1248. nameLab.text = [NSString stringWithFormat:@"%@ %@",[nameLab.text componentsSeparatedByString:@" "][0],arr[subject-1]];
  1249. } else {
  1250. nameLab.text = [NSString stringWithFormat:@"%@ %@",[nameLab.text componentsSeparatedByString:@" "][0],@"科目错误"];
  1251. }
  1252. //获取到状态下一步
  1253. [self nextWithCurrentStatu:root[@"body"][@"bigCar"][@"TYPE"]];
  1254. }else{
  1255. ShowMsg(root[@"msg"]);
  1256. }
  1257. }];
  1258. }
  1259. - (void)getStudentTrainInfos
  1260. {
  1261. if (![Util connectedToNetWork]) {
  1262. showMsgUnconnect();
  1263. return;
  1264. }
  1265. //查询学员签到列表 科目传空 查全部
  1266. NSMutableArray *arr = [NSMutableArray array];
  1267. [arr addPro:@"coachId" Value:bigCarDic[@"CoachId"]];
  1268. [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]];
  1269. NSString* method = @"getStudentTrainInfos";
  1270. [MBProgressHUD showMessage:@"正在获取计时信息" toView:self.view];
  1271. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  1272. [MBProgressHUD hideHUDForView:self.view];
  1273. if (!root) {
  1274. ShowMsg(@"请求失败");
  1275. return ;
  1276. }
  1277. if ([root[@"code"] isEqualToString:@"1"]) {
  1278. ShowMsg(root[@"body"]);
  1279. return;
  1280. }
  1281. [self reloadDetailLabWithDic:root[@"body"]];
  1282. }];
  1283. }
  1284. //上传分钟学时(批量)
  1285. - (void)uploadAppTrainPlWithSignOut:(BOOL)isSignOut
  1286. {
  1287. NSArray *minuteTrainArray = [DB_Helper quearyTrainWithClassId:classId type:bigCarTableName];
  1288. if (isSignOut) {
  1289. if (minuteTrainArray.count == 0) {
  1290. [self closeTimer];
  1291. return;
  1292. }
  1293. }
  1294. if (![Util connectedToNetWork]) {
  1295. if (isVoice) {
  1296. [Tools playAudioWithString:@"无网络连接,学时上传失败"];
  1297. }
  1298. if (isSignOut) {
  1299. [self showReUpLoad];
  1300. return;
  1301. }
  1302. [dateFormatter setDateFormat:@"HH:mm"];
  1303. NSString *timeString = [dateFormatter stringFromDate:[NSDate date]];
  1304. [dataSourceArray addObject:[NSString stringWithFormat:@"1%@ 学时上传失败!",timeString]];
  1305. return;
  1306. }
  1307. NSMutableArray *mArr = [NSMutableArray new];;
  1308. for (NSDictionary *dic in minuteTrainArray) {
  1309. NSData *responseObject = [dic[@"gps"] dataUsingEncoding:NSUTF8StringEncoding];
  1310. if (responseObject == nil) {
  1311. return;
  1312. }
  1313. NSDictionary *gpsDic = [NSJSONSerialization JSONObjectWithData:responseObject
  1314. options:NSJSONReadingMutableContainers
  1315. error:nil];
  1316. NSMutableDictionary * csDic = [NSMutableDictionary new];
  1317. [csDic setObject:gpsDic[@"lng"] forKey:@"lng"];
  1318. [csDic setObject:gpsDic[@"lat"] forKey:@"lat"];
  1319. [csDic setObject:gpsDic[@"crTime"] forKey:@"crTime"];
  1320. [mArr addObject:csDic];
  1321. }
  1322. NSString *jsonString = [self getJsonStringWithObj:mArr];
  1323. NSMutableArray *arr=[NSMutableArray array];
  1324. [arr addPro:@"stuOutId" Value:defUser.userDict[@"outId"]];
  1325. [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]];
  1326. [arr addPro:@"classId" Value:gatherTrainDic[@"classId"]];
  1327. [arr addPro:@"gpsList" Value:jsonString];
  1328. [arr addPro:@"lng" Value:[NSString stringWithFormat:@"%f",myCoordinate.longitude]];
  1329. [arr addPro:@"lat" Value:[NSString stringWithFormat:@"%f",myCoordinate.latitude]];
  1330. NSString* method = @"uploadStuGps";
  1331. if (isSignOut) {
  1332. [MBProgressHUD showMessage:@"正在补传学时" toView:self.view];
  1333. }
  1334. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  1335. if (isSignOut) {
  1336. [MBProgressHUD hideHUDForView:self.view animated:YES];
  1337. }
  1338. [self.view setUserInteractionEnabled:YES];
  1339. [dateFormatter setDateFormat:@"HH:mm"];
  1340. NSString *timeString = [dateFormatter stringFromDate:[NSDate date]];
  1341. if (!root) {
  1342. if (isSignOut) {
  1343. [gatherTrainDic setObject:@"2" forKey:@"isOver"];
  1344. [self saveGatherTrainDic];//保存至本地 可以用于断线重连
  1345. [self showReUpLoad];//重新上传选择
  1346. }
  1347. if (isVoice) {
  1348. [Tools playAudioWithString:@"学时上传失败!"];
  1349. }
  1350. [dataSourceArray addObject:[NSString stringWithFormat:@"1%@ 学时上传失败!",timeString]];
  1351. return ;
  1352. }
  1353. if ([root[@"code"] isEqualToString:@"1"]) {
  1354. if (isSignOut) {
  1355. [gatherTrainDic setObject:@"2" forKey:@"isOver"];
  1356. [self saveGatherTrainDic];//保存至本地
  1357. [self showReUpLoad];//重新上传选择
  1358. }
  1359. if (isVoice) {
  1360. [Tools playAudioWithString:[NSString stringWithFormat:@"%@,学时上传失败!",root[@"body"]]];
  1361. }
  1362. [dataSourceArray addObject:[NSString stringWithFormat:@"1%@ 学时上传失败!",timeString]];
  1363. return;
  1364. }
  1365. // ShowMsg(@"调试:位置上传成功一次");
  1366. //msg = 上传位置成功;1;1;0;0, 后面的分别表示xx时间
  1367. if (isVoice) {
  1368. [Tools playAudioWithString:@"学时上传成功!"];
  1369. }
  1370. [dataSourceArray addObject:[NSString stringWithFormat:@"0%@ 学时上传成功!",timeString]];
  1371. [DB_Helper deleteTrainWithClassId:gatherTrainDic[@"classId"] type:bigCarTableName];
  1372. //计时结束
  1373. if (isSignOut) {
  1374. [DB_Helper deleteAllTrainWithType:bigCarTableName];
  1375. [self closeTimer];
  1376. }
  1377. }];
  1378. }
  1379. //重新上传选择
  1380. - (void)showReUpLoad{
  1381. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:@"提醒" message:@"学时补传失败,已保存至手机。您可以选择立即或稍后重新上传" preferredStyle:UIAlertControllerStyleAlert];
  1382. [alertFind addAction:[UIAlertAction actionWithTitle:@"现在上传" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1383. [self uploadAppTrainPlWithSignOut:YES];
  1384. }]];
  1385. [alertFind addAction:[UIAlertAction actionWithTitle:@"以后补传" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  1386. }]];
  1387. [self presentViewController:alertFind animated:true completion:nil];
  1388. }
  1389. @end