ScanVC.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. //
  2. // ScanVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 16/4/19.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "ScanVC.h"
  9. #import "CDZQRScanView.h"
  10. #import "ScanResultVC.h"
  11. #import "MyWebViewVC.h"
  12. #import <Photos/Photos.h>
  13. #import "DES3Util.h"
  14. #import <BMKLocationkit/BMKLocationComponent.h>//引入定位功能所有的头文件(新)
  15. #import "AFNetworking.h"
  16. #import <UserNotifications/UNUserNotificationCenter.h>
  17. #define KWidth (kSize.width/2.0 + 30)
  18. typedef NS_ENUM(NSInteger, ScanType) {
  19. //惠智/多伦等模拟设备登录
  20. Huizhi_mn,
  21. //兴中正模拟设备登录
  22. Xzz_mn
  23. };
  24. @interface ScanVC ()<BMKLocationManagerDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,CDZQRScanDelegate>
  25. {
  26. //闪光灯
  27. UIView *flashlightView;
  28. UILabel *flashlightStateLabel;
  29. UIButton *flashlightBtn;
  30. //扫描结果
  31. NSString *dataString;
  32. //扫码类型
  33. ScanType locationType;
  34. //地图定位
  35. CLLocationCoordinate2D myCoordinate;
  36. }
  37. @property (nonatomic ,strong) CDZQRScanView *scanView;
  38. @property (nonatomic ,strong) UIImagePickerController *imagePicker;
  39. //扫码区域上方提示文字
  40. @property (nonatomic, strong) UILabel *topTitle;
  41. #pragma mark - 底部几个功能:开启闪光灯、相册、我的二维码
  42. //底部显示的功能项
  43. @property (nonatomic, strong) UIView *bottomItemsView;
  44. //相册
  45. @property (nonatomic, strong) UIButton *btnPhoto;
  46. //闪光灯
  47. @property (nonatomic, strong) UIButton *btnFlash;
  48. //闪关灯开启状态记录
  49. @property(nonatomic,assign)BOOL isOpenFlash;
  50. @end
  51. @implementation ScanVC
  52. - (void)viewDidLoad {
  53. [super viewDidLoad];
  54. //vc的基本设置
  55. self.view.backgroundColor = [UIColor blackColor];
  56. self.title = @"二维码扫描";
  57. [self configNavigationBar];
  58. //
  59. [self.view addSubview:self.scanView];
  60. //
  61. [self drawTitle];
  62. //
  63. [self drawBottomItems];
  64. [[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
  65. }];
  66. UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
  67. BOOL isEnable = (UIUserNotificationTypeNone == setting.types) ? NO : YES;
  68. if (!isEnable) {
  69. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"打开APP推送功能,能够更及时的进行计时过程验证哦!!!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"不打开" otherButtonTitles:@[@"打开推送"] otherButtonStyles:nil completion:^(NSUInteger selectedOtherButtonIndex) {
  70. if (selectedOtherButtonIndex == 0) {
  71. UIApplication *application = [UIApplication sharedApplication];
  72. NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
  73. if ([application canOpenURL:url]) {
  74. if ([application respondsToSelector:@selector(openURL:options:completionHandler:)]) {
  75. [application openURL:url options:@{} completionHandler:nil];
  76. } else {
  77. [application openURL:url];
  78. }
  79. }
  80. }
  81. }];
  82. }
  83. }
  84. - (void)changeFlash {
  85. [self.scanView changeTorch];
  86. self.isOpenFlash = !self.isOpenFlash;
  87. if (self.isOpenFlash) {
  88. [_btnFlash setImage:[UIImage imageNamed:@"qrcode_scan_btn_flash_down"] forState:UIControlStateNormal];
  89. }
  90. else {
  91. [_btnFlash setImage:[UIImage imageNamed:@"qrcode_scan_btn_flash_nor"] forState:UIControlStateNormal];
  92. }
  93. }
  94. -(void)viewWillAppear:(BOOL)animated
  95. {
  96. [super viewWillAppear:animated];
  97. self.scanView.delegate = self;
  98. [self.scanView startScanning];
  99. }
  100. -(void)viewWillDisappear:(BOOL)animated
  101. {
  102. [super viewWillDisappear:animated];
  103. [self.scanView stopScanning];
  104. self.scanView.delegate = nil;
  105. }
  106. -(void)scanBlock:(MyBlockType)block
  107. {
  108. scanBlock = block;
  109. }
  110. #pragma mark - 绘制扫描区域
  111. - (void)drawTitle
  112. {
  113. if (!_topTitle)
  114. {
  115. CGRect scanRect = self.scanView.scanRect;
  116. self.topTitle = [[UILabel alloc]init];
  117. _topTitle.bounds = CGRectMake(0, 0, scanRect.size.width*2/3, 0);
  118. _topTitle.font = [UIFont systemFontOfSize:15];
  119. _topTitle.textAlignment = NSTextAlignmentCenter;
  120. _topTitle.numberOfLines = 0;
  121. _topTitle.text = @"将取景框对准二维码即可自动扫描";
  122. _topTitle.textColor = [UIColor whiteColor];
  123. [_topTitle sizeToFit];
  124. _topTitle.center = CGPointMake(CGRectGetWidth(self.view.frame)/2, CGRectGetMinY(scanRect)-_topTitle.height/2-15);
  125. [self.view addSubview:_topTitle];
  126. }
  127. }
  128. - (void)drawBottomItems
  129. {
  130. if (_bottomItemsView) {
  131. return;
  132. }
  133. CGFloat bottomBarH = 100;
  134. self.bottomItemsView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.view.frame)-bottomBarH-kNavOffSet-kSafeAreaBottomHeight,
  135. CGRectGetWidth(self.view.frame), bottomBarH+kSafeAreaBottomHeight)];
  136. _bottomItemsView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.6];
  137. [self.view addSubview:_bottomItemsView];
  138. CGSize size = CGSizeMake(65, 87);
  139. self.btnFlash = [[UIButton alloc]init];
  140. _btnFlash.bounds = CGRectMake(0, 0, size.width, size.height);
  141. _btnFlash.center = CGPointMake(CGRectGetWidth(_bottomItemsView.frame)/2, bottomBarH/2);
  142. [_btnFlash setImage:[UIImage imageNamed:@"qrcode_scan_btn_flash_nor"] forState:UIControlStateNormal];
  143. [_btnFlash addTarget:self action:@selector(changeFlash) forControlEvents:UIControlEventTouchUpInside];
  144. self.btnPhoto = [[UIButton alloc]init];
  145. _btnPhoto.bounds = _btnFlash.bounds;
  146. _btnPhoto.center = CGPointMake(CGRectGetWidth(_bottomItemsView.frame)*2/3, bottomBarH/2);
  147. [_btnPhoto setImage:[UIImage imageNamed:@"qrcode_scan_btn_photo_nor"] forState:UIControlStateNormal];
  148. [_btnPhoto setImage:[UIImage imageNamed:@"qrcode_scan_btn_photo_down"] forState:UIControlStateHighlighted];
  149. [_btnPhoto addTarget:self action:@selector(openLibary) forControlEvents:UIControlEventTouchUpInside];
  150. [_bottomItemsView addSubview:_btnFlash];
  151. // [_bottomItemsView addSubview:_btnPhoto];
  152. }
  153. #pragma mark - imagePickerDelegate
  154. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(nonnull NSDictionary<NSString *,id> *)info{
  155. [picker dismissViewControllerAnimated:YES completion:nil];
  156. UIImage *image = info[UIImagePickerControllerOriginalImage];
  157. NSString *result = [self messageFromQRCodeImage:image];
  158. if (result.length == 0) {
  159. [self showAlert:@"未识别到二维码"];
  160. return;
  161. }
  162. [self showAlert:result];
  163. }
  164. #pragma mark - 扫描结果 scanViewDelegate
  165. - (void)scanView:(CDZQRScanView *)scanView pickUpMessage:(NSString *)message
  166. {
  167. [scanView stopScanning];
  168. if ([message containsString:@"#DECODE#"] && message.length > 8) {
  169. //程序内某些验证
  170. NSString *testString = [DES3Util decrypt:[message substringFromIndex:8]];
  171. NSLog(@"\n原完整内容: %@ \n解密后: #DECODE#%@",message,testString);
  172. if (testString == nil) {
  173. [self showResultString:@"二维码内容格式错误(#DECODE#+异常字符串)" title:nil];
  174. return;
  175. }
  176. //集中理论计时签到/签退
  177. if ([testString containsString:@"#LNJP#theory"]) {
  178. if ([_type isEqualToString:@"2"]) {
  179. [self showResultString:@"二维码类型错误,请扫描\"模拟设备登录\"二维码" title:@"模拟设备登录"];
  180. return;
  181. }
  182. NSArray *array = [testString componentsSeparatedByString:@"@@"];
  183. testString = [testString substringFromIndex:6];
  184. NSDictionary *dic = @{@"scanType":[array lastObject],@"dataString":[DES3Util encrypt:testString]};
  185. if (scanBlock) {
  186. [self.navigationController popViewControllerAnimated:YES];
  187. scanBlock(dic);
  188. }
  189. return;
  190. }
  191. //模拟终端登录 #DECODE#LNJP#simulatorLogin@@132456@@BFEBFBFF000206A7
  192. if ([testString containsString:@"#LNJP#simulatorLogin"]) {
  193. [Tools confirmImeiWithLogType:@"3" successBlock:^{
  194. dataString = testString;
  195. if (scanBlock) {
  196. if ([self.type isEqualToString:@"2"]) {//来自模拟vc
  197. locationType = Xzz_mn;
  198. [self getMyLocation];
  199. }else if ([self.type isEqualToString:@"1"]){//来自homebase
  200. locationType = Xzz_mn;
  201. [self getMyLocation];
  202. }else{
  203. [self showResultString:@"二维码类型错误" title:nil];
  204. }
  205. }
  206. }];
  207. return;
  208. }
  209. //惠智模拟计时 #LNJP#huizhi@@BFEBFBFF000206A7@@1530258491165
  210. //多伦
  211. if ([testString containsString:@"#LNJP#huizhi"] || [testString containsString:@"#LNJP#other"]) {
  212. dataString = testString;
  213. locationType = Huizhi_mn;
  214. [self getMyLocation];
  215. return;
  216. }
  217. [self showResultString:message title:@"扫描结果"];
  218. return;
  219. }
  220. if([self.type isEqualToString:@"2"]){
  221. [self showResultString:@"二维码类型错误,请扫描\"模拟设备登录\"二维码" title:@"模拟设备登录"];
  222. return;
  223. }
  224. //进某网址
  225. if ([self.type isEqualToString:@"1"]) {
  226. if ([message hasPrefix:@"http://"] || [message hasPrefix:@"https://"]) {
  227. MyWebViewVC *vc = [MyWebViewVC new];
  228. vc.urlString = message;
  229. NSArray *vcs = self.navigationController.childViewControllers;
  230. NSMutableArray *arr = [NSMutableArray arrayWithArray:vcs];
  231. [arr replaceObjectAtIndex:vcs.count-1 withObject:vc];
  232. [self.navigationController setViewControllers:arr animated:YES];
  233. return;
  234. }
  235. [self showResultString:message title:@"扫描结果"];
  236. }
  237. }
  238. #pragma mark - 打开相册
  239. - (void)openLibary{
  240. if (![self isLibaryAuthStatusCorrect]) {
  241. [self showAlert:@"需要相册权限"];
  242. return;
  243. }
  244. [self presentViewController:self.imagePicker animated:YES completion:nil];
  245. }
  246. - (NSString *)messageFromQRCodeImage:(UIImage *)image{
  247. if (!image) {
  248. return nil;
  249. }
  250. CIContext *context = [CIContext contextWithOptions:nil];
  251. CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:context options:@{CIDetectorAccuracy:CIDetectorAccuracyHigh}];
  252. CIImage *ciImage = [CIImage imageWithCGImage:image.CGImage];
  253. NSArray *features = [detector featuresInImage:ciImage];
  254. if (features.count == 0) {
  255. return nil;
  256. }
  257. CIQRCodeFeature *feature = features.firstObject;
  258. return feature.messageString;
  259. }
  260. - (BOOL)isLibaryAuthStatusCorrect{
  261. PHAuthorizationStatus authStatus = [PHPhotoLibrary authorizationStatus];
  262. if (authStatus == PHAuthorizationStatusNotDetermined || authStatus == PHAuthorizationStatusAuthorized) {
  263. return YES;
  264. }
  265. return NO;
  266. }
  267. #pragma mark - 定位
  268. -(void)getMyLocation{
  269. BOOL isOpenTwo = [defUser.userDict[@"mnqTwoOpen"] isEqualToString:@"0"];
  270. BOOL isOpenThree = [defUser.userDict[@"mnqThreeOpen"] isEqualToString:@"0"];
  271. if (isOpenThree && isOpenTwo) {
  272. showMsgByAlert(self, @"暂未开启模拟计时");
  273. return;
  274. }
  275. //开启百度定位 DistanceFilter:将被通知任何移动(若=10,表示超出10米才会回调位置信息)
  276. [[MapManager sharedManager] updateLocationWithDistanceFilter:1 CompleteBlock:^(BOOL success, CLLocation * _Nonnull location) {
  277. if (success) {
  278. self->myCoordinate = location.coordinate;
  279. if (self->locationType == Xzz_mn) {
  280. [self MNQLogin];
  281. }else if(self->locationType == Huizhi_mn){
  282. [self HuiZhiMNQLogin];
  283. }
  284. }
  285. }];
  286. }
  287. #pragma mark - 模拟设备登录
  288. - (void)MNQLogin{
  289. //dataString #LNJP#simulatorLogin @@ BFEBFBFF000206A7
  290. NSArray *arr = [dataString componentsSeparatedByString:@"@@"];
  291. NSString *account = defUser.userDict[@"loginCode"];
  292. NSString *urlStr = [NSString stringWithFormat:@"%@lnmn/admin/phoneLogin",@"http://122.lnjppt.com/"];//@"http://192.168.1.237:8083/"
  293. NSMutableString *paramStr = [NSMutableString new];
  294. [paramStr appendString:[NSString stringWithFormat:@"%@",account]];//uname
  295. [paramStr appendString:[NSString stringWithFormat:@";%@",arr[1]]];//mnqSn
  296. [paramStr appendString:[NSString stringWithFormat:@";%@",defUser.userDict[@"city"]]];//dqbh
  297. [paramStr appendString:[NSString stringWithFormat:@";%f",myCoordinate.longitude]];//lng
  298. [paramStr appendString:[NSString stringWithFormat:@";%f",myCoordinate.latitude]];//lat
  299. //设置请求管理器
  300. AFHTTPSessionManager *afSessionManager = [AFHTTPSessionManager manager];
  301. afSessionManager.requestSerializer = [AFJSONRequestSerializer serializer];
  302. afSessionManager.responseSerializer = [AFHTTPResponseSerializer serializer];
  303. afSessionManager.responseSerializer.acceptableContentTypes = [afSessionManager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
  304. afSessionManager.requestSerializer.timeoutInterval = 15;
  305. NSLog(@"%@",urlStr);
  306. [MBProgressHUD showMessage:@"正在登录模拟设备" toView:self.view];
  307. [afSessionManager POST:urlStr parameters:@{@"params":[DES3Util encrypt:paramStr]} headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
  308. //请求成功
  309. [MBProgressHUD hideHUDForView:self.view];
  310. if (responseObject == nil) {
  311. [self showResultString:@"服务异常:无数据返回" title:@"登录失败"];
  312. return;
  313. }
  314. NSDictionary *root = [NSJSONSerialization JSONObjectWithData:responseObject
  315. options:NSJSONReadingMutableContainers
  316. error:nil];
  317. /*
  318. code=0—登录成功
  319. code=1—用户不存在
  320. code=2—未绑定报名信息
  321. code=3—当前培训阶段无法参与模拟训练
  322. code=4—当前模拟设备未绑定
  323. code=5—该设备已有学员在训练中
  324. code=6—模拟教室信息不存在
  325. code=7—您当前不在模拟教室有效范围内
  326. */
  327. if (![root[@"code"] isEqualToString:@"0"]) {
  328. [self showResultString:root[@"msg"] title:@"登录失败"];
  329. return;
  330. }
  331. //A 在 码I 计时; B 在 码II 计时; C 未计时,码III 未计时
  332. /*
  333. C扫码I/II,服务器返回code=1;
  334. A扫码I,服务器返回code=0;
  335. */
  336. NSLog(@"模拟设备登录成功123---urlString---><>%@,\n%@",urlStr,root);
  337. if ([self.type isEqualToString:@"2"]) {//function个人界面
  338. [self.navigationController popViewControllerAnimated:NO];
  339. if (scanBlock) {
  340. scanBlock(@"success");
  341. }
  342. }else if([self.type isEqualToString:@"1"]){//如果是homebase进来的
  343. [self.navigationController popViewControllerAnimated:NO];
  344. if (scanBlock) {
  345. scanBlock(@{@"scanType":@"MNQTrain"});
  346. }
  347. }
  348. } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
  349. NSLog(@"请求失败123----><>%@",error);
  350. [MBProgressHUD hideHUDForView:self.view];
  351. NSString *reason = @"请求失败";
  352. if ([error.localizedDescription isEqualToString:@"The request timed out."]) {
  353. //,@"请求超时"
  354. reason = @"连接超时,请检查手机网络";
  355. }
  356. [self showResultString:reason title:@"登录失败"];
  357. }];
  358. }
  359. #pragma mark - 惠智模拟设备登录
  360. - (void)HuiZhiMNQLogin{
  361. //dataString #LNJP#simulatorLogin @@ BFEBFBFF000206A7 @@ 时间戳
  362. NSArray *arr = [dataString componentsSeparatedByString:@"@@"];
  363. NSString *account = defUser.userDict[@"loginCode"];
  364. NSString *urlStr = [NSString stringWithFormat:@"%@appservice/lnsimulator/phoneLogin",@"http://app.lnjppt.com/"];//@"http://218.85.55.253:9091/ln" @"http://192.168.1.3:8081/ln"
  365. NSMutableString *paramStr = [NSMutableString new];
  366. // [paramStr appendString:arr[1]];//uuid
  367. [paramStr appendString:[NSString stringWithFormat:@"%@",account]];//uname
  368. [paramStr appendString:[NSString stringWithFormat:@";%@",arr[1]]];//mnqSn
  369. [paramStr appendString:[NSString stringWithFormat:@";%@",defUser.userDict[@"city"]]];//dqbh
  370. [paramStr appendString:[NSString stringWithFormat:@";%f",myCoordinate.longitude]];//lng
  371. [paramStr appendString:[NSString stringWithFormat:@";%f",myCoordinate.latitude]];//lat
  372. [paramStr appendString:[NSString stringWithFormat:@";%@",arr[2]]];
  373. // NSTimeInterval timeI = [[NSDate date] timeIntervalSince1970] * 1000;
  374. // [paramStr appendString:[NSString stringWithFormat:@";%.0f",timeI]];
  375. //设置请求管理器
  376. AFHTTPSessionManager *afSessionManager = [AFHTTPSessionManager manager];
  377. afSessionManager.requestSerializer = [AFJSONRequestSerializer serializer];
  378. afSessionManager.responseSerializer = [AFHTTPResponseSerializer serializer];
  379. afSessionManager.responseSerializer.acceptableContentTypes = [afSessionManager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
  380. afSessionManager.requestSerializer.timeoutInterval = 15;
  381. NSLog(@"%@ \n params:{%@}",urlStr,paramStr);
  382. [MBProgressHUD showMessage:@"正在登录模拟设备" toView:self.view];
  383. [afSessionManager POST:urlStr parameters:@{@"params":[DES3Util encrypt:paramStr]} headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
  384. //请求成功
  385. [MBProgressHUD hideHUDForView:self.view];
  386. if (responseObject == nil) {
  387. [self showResultString:@"服务异常:无数据返回" title:@"登录失败"];
  388. return;
  389. }
  390. NSDictionary *root = [NSJSONSerialization JSONObjectWithData:responseObject
  391. options:NSJSONReadingMutableContainers
  392. error:nil];
  393. NSLog(@"惠智/多伦:%@---->: %@",urlStr,root);
  394. if ([root[@"code"] isEqualToString:@"90"]) {
  395. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:root[@"msg"] preferredStyle:UIAlertControllerStyleAlert];
  396. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  397. [LoginViewController loginFromVC:self];
  398. }]];
  399. [self presentViewController:alertFind animated:true completion:nil];
  400. return;
  401. }
  402. if (![root[@"code"] isEqualToString:@"0"]) {
  403. [self showResultString:root[@"msg"] title:@"登录失败"];
  404. return;
  405. }
  406. NSString *carNum = nil;
  407. NSDictionary *body = root[@"body"];
  408. if (body && [body isKindOfClass:[NSDictionary class]]) {
  409. NSDictionary *map = body[@"map"];
  410. if (map && [map isKindOfClass:[NSDictionary class]]) {
  411. carNum = [NSString stringWithFormat:@"%@",map[@"carnum"]];
  412. }
  413. }
  414. NSString *successStr = @"模拟设备已登录";
  415. if (carNum && carNum.length != 0) {
  416. successStr = [NSString stringWithFormat:@"%@,欢迎您!\n已成功登录模拟设备【%@】,祝您体验愉快",defUser.userName,carNum];
  417. }
  418. [self showResultString:successStr title:@"登录成功"];
  419. } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
  420. NSLog(@"请求失败123----><>%@",error);
  421. [MBProgressHUD hideHUDForView:self.view];
  422. NSString *reason = @"请求失败";
  423. if ([error.localizedDescription isEqualToString:@"The request timed out."]) {
  424. //,@"请求超时"
  425. reason = @"连接超时,请检查手机网络";
  426. }
  427. [self showResultString:reason title:@"登录失败"];
  428. }];
  429. }
  430. #pragma mark - alert 提示
  431. -(void)showResultString:(NSString *)str title:(NSString *)title{
  432. ScanResultVC *vc = [ScanResultVC new];
  433. vc.resultStr = str;
  434. vc.navigationItem.title = title;
  435. if (self == nil) {//请求网络数据到一半,返回首页
  436. return;
  437. }
  438. NSArray *vcs = self.navigationController.childViewControllers;
  439. NSMutableArray *arr = [NSMutableArray arrayWithArray:vcs];
  440. if (vcs.count > 1) {
  441. [arr replaceObjectAtIndex:vcs.count-1 withObject:vc];
  442. }else {
  443. [arr addObject:vc];
  444. }
  445. [self.navigationController setViewControllers:arr animated:YES];
  446. }
  447. - (void)showAlert:(NSString *)message {
  448. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:message preferredStyle:UIAlertControllerStyleAlert];
  449. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"好" style:UIAlertActionStyleCancel handler:nil];
  450. [alert addAction:cancelAction];
  451. [self presentViewController:alert animated:YES completion:nil];
  452. }
  453. #pragma mark - get
  454. - (CDZQRScanView *)scanView{
  455. if (!_scanView) {
  456. _scanView = [[CDZQRScanView alloc]initWithFrame:CGRectMake(0, 0, kSize.width, kSize.height-kNavOffSet-kSafeAreaBottomHeight)];
  457. _scanView.delegate = self;
  458. _scanView.showBorderLine = YES;
  459. _scanView.scanLineColor = [UIColor cyanColor];
  460. _scanView.cornerLineColor = [UIColor whiteColor];
  461. // CGSize scanSize = CGSizeMake(_scanView.width * 2/3, _scanView.width * 2/3);
  462. // _scanView.scanRect = CGRectMake((_scanView.size.width - scanSize.width)/2, (_scanView.size.height - 100 - scanSize.height)/2, scanSize.width, scanSize.height);
  463. }
  464. return _scanView;
  465. }
  466. - (UIImagePickerController *)imagePicker{
  467. if (!_imagePicker) {
  468. _imagePicker = [[UIImagePickerController alloc]init];
  469. _imagePicker.delegate = self;
  470. _imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  471. }
  472. return _imagePicker;
  473. }
  474. - (void)didReceiveMemoryWarning {
  475. [super didReceiveMemoryWarning];
  476. }
  477. @end