Commit 8177a10d5ea7280c54660a2ba87f7296374df80c
1 parent
32fe407a
增加新的提示框,优化代码
Showing
3 changed files
with
477 additions
and
280 deletions
CNLiveBPersonalVerificationModule/Classes/CNBPersonCardInfo/Controller/ApplyForShootController.m
| ... | ... | @@ -8,7 +8,6 @@ |
| 8 | 8 | |
| 9 | 9 | #import "ApplyForShootController.h" |
| 10 | 10 | #import <AipOcrSdk/AipOcrSdk.h> |
| 11 | -#import <objc/runtime.h> | |
| 12 | 11 | #import "AFNetworking.h" |
| 13 | 12 | #import "ApplyForShootCell.h" |
| 14 | 13 | #import "ApplyForConfirmCell.h" |
| ... | ... | @@ -29,7 +28,8 @@ |
| 29 | 28 | #import <CNLiveImagePickerController/TZImagePickerController.h> |
| 30 | 29 | #import <CNLiveImagePickerController/TZImageManager.h> |
| 31 | 30 | #import <CNLiveCommonCategory/CNLiveCommonCategory.h> |
| 32 | -@interface ApplyForShootController ()<UIAlertViewDelegate,UITableViewDelegate,UITableViewDataSource,UINavigationControllerDelegate, UIImagePickerControllerDelegate> | |
| 31 | +#import "CNLiveIDCardAuthAlertView.h" | |
| 32 | +@interface ApplyForShootController ()<UITableViewDelegate,UITableViewDataSource,UINavigationControllerDelegate, UIImagePickerControllerDelegate, IDCardAuthAlertViewDelegate> | |
| 33 | 33 | |
| 34 | 34 | @property (nonatomic, strong) UITableView *tableView; |
| 35 | 35 | @property (nonatomic, strong) NSArray <AgreementModel*>*dataArray; |
| ... | ... | @@ -66,50 +66,20 @@ |
| 66 | 66 | [super viewDidLoad]; |
| 67 | 67 | self.title = @"拍摄照片"; |
| 68 | 68 | self.view.backgroundColor = [UIColor whiteColor]; |
| 69 | + self.edgesForExtendedLayout = UIRectEdgeNone; | |
| 70 | +// self.extendedLayoutIncludesOpaqueBars = YES; | |
| 69 | 71 | self.imageDatas = [NSMutableArray array]; |
| 70 | 72 | self.pickerVC = [[UIImagePickerController alloc] init]; |
| 71 | 73 | self.pickerVC.delegate = self; |
| 72 | 74 | [[AipOcrService shardService] authWithAK:BDAppKey andSK:BDSecret]; |
| 73 | 75 | [self loadData]; |
| 74 | 76 | [self.view addSubview:self.tableView]; |
| 75 | -// if (@available(iOS 11.0, *)) { | |
| 76 | -// self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; | |
| 77 | -// }else{ | |
| 78 | -// self.automaticallyAdjustsScrollViewInsets = NO; | |
| 79 | -// } | |
| 80 | - [self configCallback]; | |
| 81 | - | |
| 82 | -} | |
| 83 | - | |
| 84 | -- (void)loadData { | |
| 85 | - | |
| 86 | - NSArray *array = @[ | |
| 87 | - @{ | |
| 88 | - @"shootTitle":@"第一步", | |
| 89 | - @"shootImage":@"observer_idcard_front", | |
| 90 | - @"isFront":@"1", | |
| 91 | - @"isOwn":@"0" | |
| 92 | - }, | |
| 93 | - @{ | |
| 94 | - @"shootTitle":@"第二步", | |
| 95 | - @"shootImage":@"observer_idcard_back", | |
| 96 | - @"isFront":@"0", | |
| 97 | - @"isOwn":@"0" | |
| 98 | - }, | |
| 99 | - @{ | |
| 100 | - @"shootTitle":@"第三步", | |
| 101 | - @"shootImage":@"observer_idcard_own", | |
| 102 | - @"isFront":@"0", | |
| 103 | - @"isOwn":@"1" | |
| 104 | - }, | |
| 105 | - ]; | |
| 106 | - NSMutableArray *arrayM = [NSMutableArray array]; | |
| 107 | - for (NSDictionary *dic in array) { | |
| 108 | - AgreementModel *model = [AgreementModel mj_objectWithKeyValues:dic]; | |
| 109 | - [arrayM addObject:model]; | |
| 77 | + if (@available(iOS 11.0, *)) { | |
| 78 | + self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; | |
| 79 | + }else{ | |
| 80 | + self.automaticallyAdjustsScrollViewInsets = NO; | |
| 110 | 81 | } |
| 111 | - self.dataArray = arrayM.copy; | |
| 112 | - [self.tableView reloadData]; | |
| 82 | + [self configCallback]; | |
| 113 | 83 | |
| 114 | 84 | } |
| 115 | 85 | |
| ... | ... | @@ -119,6 +89,9 @@ |
| 119 | 89 | |
| 120 | 90 | // 这是默认的识别成功的回调 |
| 121 | 91 | _successHandler = ^(id result){ |
| 92 | + dispatch_async(dispatch_get_main_queue(), ^{ | |
| 93 | + [weakSelf dismissViewControllerAnimated:YES completion:nil]; | |
| 94 | + }); | |
| 122 | 95 | if (!weakSelf.isHandler) { |
| 123 | 96 | return ; |
| 124 | 97 | } |
| ... | ... | @@ -132,7 +105,7 @@ |
| 132 | 105 | if (weakSelf.isFont) { ///////// 前 |
| 133 | 106 | if ([dict count] < 6) { |
| 134 | 107 | [[NSOperationQueue mainQueue] addOperationWithBlock:^{ |
| 135 | - UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:@"照片不规范,信息不全,请重新拍摄" delegate:weakSelf cancelButtonTitle:@"确定" otherButtonTitles:nil]; | |
| 108 | + CNLiveIDCardAuthAlertView *alertView = [[CNLiveIDCardAuthAlertView alloc] initWithTitle:title message:@"照片不规范,信息不全,请重新拍摄" delegate:weakSelf]; | |
| 136 | 109 | [alertView show]; |
| 137 | 110 | weakSelf.isFontSucc = NO; |
| 138 | 111 | NSIndexPath *index = [NSIndexPath indexPathForRow:0 inSection:0]; |
| ... | ... | @@ -146,7 +119,7 @@ |
| 146 | 119 | } else { |
| 147 | 120 | if ([dict count] < 3) { |
| 148 | 121 | [[NSOperationQueue mainQueue] addOperationWithBlock:^{ |
| 149 | - UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:@"照片不规范,信息不全,请重新拍摄" delegate:weakSelf cancelButtonTitle:@"确定" otherButtonTitles:nil]; | |
| 122 | + CNLiveIDCardAuthAlertView *alertView = [[CNLiveIDCardAuthAlertView alloc] initWithTitle:title message:@"照片不规范,信息不全,请重新拍摄" delegate:weakSelf]; | |
| 150 | 123 | [alertView show]; |
| 151 | 124 | weakSelf.isBackSucc = NO; |
| 152 | 125 | NSIndexPath *index = [NSIndexPath indexPathForRow:1 inSection:0]; |
| ... | ... | @@ -158,7 +131,7 @@ |
| 158 | 131 | return ; |
| 159 | 132 | } else if ([[CNLiveTimeTools getyyMMddStr] integerValue] > [dict[@"失效日期"][@"words"] integerValue] && ![[NSString stringWithFormat:@"%@",dict[@"失效日期"][@"words"]] isEqualToString:@"长期"]) { |
| 160 | 133 | [[NSOperationQueue mainQueue] addOperationWithBlock:^{ |
| 161 | - UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:@"身份证已失效,请重新拍摄" delegate:weakSelf cancelButtonTitle:@"确定" otherButtonTitles:nil]; | |
| 134 | + CNLiveIDCardAuthAlertView *alertView = [[CNLiveIDCardAuthAlertView alloc] initWithTitle:title message:@"身份证已失效,请重新拍摄" delegate:weakSelf]; | |
| 162 | 135 | [alertView show]; |
| 163 | 136 | weakSelf.isBackSucc = NO; |
| 164 | 137 | NSIndexPath *index = [NSIndexPath indexPathForRow:1 inSection:0]; |
| ... | ... | @@ -186,7 +159,7 @@ |
| 186 | 159 | }else{ |
| 187 | 160 | [message appendFormat:@"%@: %@\n", key, obj]; |
| 188 | 161 | [[NSOperationQueue mainQueue] addOperationWithBlock:^{ |
| 189 | - UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:@"照片不规范,获取信息失败,请重新拍摄" delegate:weakSelf cancelButtonTitle:@"确定" otherButtonTitles:nil]; | |
| 162 | + CNLiveIDCardAuthAlertView *alertView = [[CNLiveIDCardAuthAlertView alloc] initWithTitle:title message:@"照片不规范,获取信息失败,请重新拍摄" delegate:weakSelf]; | |
| 190 | 163 | [alertView show]; |
| 191 | 164 | weakSelf.isDataSucc = NO; |
| 192 | 165 | if (weakSelf.isFont) { |
| ... | ... | @@ -221,7 +194,10 @@ |
| 221 | 194 | weakSelf.idCardNo = dict[@"公民身份号码"][@"words"]; |
| 222 | 195 | weakSelf.address = dict[@"住址"][@"words"]; |
| 223 | 196 | weakSelf.isFontSucc = YES; |
| 224 | - | |
| 197 | + NSString *message = [NSString stringWithFormat:@"姓名:%@\n身份证号码:%@\n住址:%@",weakSelf.realName,weakSelf.idCardNo,weakSelf.address]; | |
| 198 | + CNLiveIDCardAuthAlertView *alertView = [[CNLiveIDCardAuthAlertView alloc] initWithTitle:@"请确认身份证信息是否准确" message:message delegate:weakSelf]; | |
| 199 | + alertView.messageLabTextAlignmentLeft = YES; | |
| 200 | + [alertView show]; | |
| 225 | 201 | NSIndexPath *index = [NSIndexPath indexPathForRow:0 inSection:0]; |
| 226 | 202 | ApplyForShootCell *cell = [weakSelf.tableView cellForRowAtIndexPath:index]; |
| 227 | 203 | cell.imgV.image = weakSelf.fontImage; |
| ... | ... | @@ -256,7 +232,7 @@ |
| 256 | 232 | if (weakSelf.isFont) { |
| 257 | 233 | if ([array count] < 6) { |
| 258 | 234 | [[NSOperationQueue mainQueue] addOperationWithBlock:^{ |
| 259 | - UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:@"照片不规范,信息不全,请重新拍摄" delegate:weakSelf cancelButtonTitle:@"确定" otherButtonTitles:nil]; | |
| 235 | + CNLiveIDCardAuthAlertView *alertView = [[CNLiveIDCardAuthAlertView alloc] initWithTitle:title message:@"照片不规范,信息不全,请重新拍摄" delegate:weakSelf]; | |
| 260 | 236 | [alertView show]; |
| 261 | 237 | weakSelf.isFontSucc = NO; |
| 262 | 238 | NSIndexPath *index = [NSIndexPath indexPathForRow:0 inSection:0]; |
| ... | ... | @@ -270,7 +246,7 @@ |
| 270 | 246 | } else { |
| 271 | 247 | if ([array count] < 3) { |
| 272 | 248 | [[NSOperationQueue mainQueue] addOperationWithBlock:^{ |
| 273 | - UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:@"照片不规范,信息不全,请重新拍摄" delegate:weakSelf cancelButtonTitle:@"确定" otherButtonTitles:nil]; | |
| 249 | + CNLiveIDCardAuthAlertView *alertView = [[CNLiveIDCardAuthAlertView alloc] initWithTitle:title message:@"照片不规范,信息不全,请重新拍摄" delegate:weakSelf]; | |
| 274 | 250 | [alertView show]; |
| 275 | 251 | weakSelf.isBackSucc = NO; |
| 276 | 252 | NSIndexPath *index = [NSIndexPath indexPathForRow:1 inSection:0]; |
| ... | ... | @@ -289,7 +265,7 @@ |
| 289 | 265 | }else{ |
| 290 | 266 | [message appendFormat:@"%@\n", obj]; |
| 291 | 267 | [[NSOperationQueue mainQueue] addOperationWithBlock:^{ |
| 292 | - UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:@"照片不规范,信息获取失败,请重新拍摄" delegate:weakSelf cancelButtonTitle:@"确定" otherButtonTitles:nil]; | |
| 268 | + CNLiveIDCardAuthAlertView *alertView = [[CNLiveIDCardAuthAlertView alloc] initWithTitle:title message:@"照片不规范,信息获取失败,请重新拍摄" delegate:weakSelf]; | |
| 293 | 269 | [alertView show]; |
| 294 | 270 | weakSelf.isDataSucc = NO; |
| 295 | 271 | if (weakSelf.isFont) { |
| ... | ... | @@ -328,7 +304,10 @@ |
| 328 | 304 | } |
| 329 | 305 | }]; |
| 330 | 306 | } |
| 331 | - | |
| 307 | + NSString *message = [NSString stringWithFormat:@"姓名:%@\n身份证号码:%@\n住址:%@",weakSelf.realName,weakSelf.idCardNo,weakSelf.address]; | |
| 308 | + CNLiveIDCardAuthAlertView *alertView = [[CNLiveIDCardAuthAlertView alloc] initWithTitle:@"请确认身份证信息是否准确" message:message delegate:weakSelf]; | |
| 309 | + alertView.messageLabTextAlignmentLeft = YES; | |
| 310 | + [alertView show]; | |
| 332 | 311 | NSIndexPath *index = [NSIndexPath indexPathForRow:0 inSection:0]; |
| 333 | 312 | ApplyForShootCell *cell = [weakSelf.tableView cellForRowAtIndexPath:index]; |
| 334 | 313 | cell.imgV.image = weakSelf.fontImage; |
| ... | ... | @@ -355,7 +334,7 @@ |
| 355 | 334 | }else{ |
| 356 | 335 | [message appendFormat:@"%@", result]; |
| 357 | 336 | [[NSOperationQueue mainQueue] addOperationWithBlock:^{ |
| 358 | - UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:@"照片识别失败,请重试" delegate:weakSelf cancelButtonTitle:@"确定" otherButtonTitles:nil]; | |
| 337 | + CNLiveIDCardAuthAlertView *alertView = [[CNLiveIDCardAuthAlertView alloc] initWithTitle:title message:@"照片识别失败,请重试" delegate:weakSelf]; | |
| 359 | 338 | [alertView show]; |
| 360 | 339 | if (weakSelf.isFont) { |
| 361 | 340 | weakSelf.isFontSucc = NO; |
| ... | ... | @@ -377,6 +356,9 @@ |
| 377 | 356 | }; |
| 378 | 357 | |
| 379 | 358 | _failHandler = ^(NSError *error){ |
| 359 | + dispatch_async(dispatch_get_main_queue(), ^{ | |
| 360 | + [weakSelf dismissViewControllerAnimated:YES completion:nil]; | |
| 361 | + }); | |
| 380 | 362 | if (!weakSelf.isHandler) { |
| 381 | 363 | return ; |
| 382 | 364 | } |
| ... | ... | @@ -390,7 +372,7 @@ |
| 390 | 372 | errorMsg = @"识别失败,请重拍"; |
| 391 | 373 | } |
| 392 | 374 | [[NSOperationQueue mainQueue] addOperationWithBlock:^{ |
| 393 | - UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"识别结果" message:[NSString stringWithFormat:@"%@",errorMsg] delegate:weakSelf cancelButtonTitle:@"确定" otherButtonTitles:nil]; | |
| 375 | + CNLiveIDCardAuthAlertView *alertView = [[CNLiveIDCardAuthAlertView alloc] initWithTitle:@"识别结果" message:[NSString stringWithFormat:@"%@",errorMsg] delegate:weakSelf]; | |
| 394 | 376 | [alertView show]; |
| 395 | 377 | if (weakSelf.isFont) { |
| 396 | 378 | weakSelf.isFontSucc = NO; |
| ... | ... | @@ -411,75 +393,8 @@ |
| 411 | 393 | }; |
| 412 | 394 | } |
| 413 | 395 | |
| 414 | -#pragma mark - 调用百度SDK 拍照Action !!!!!!!!!!!!!!!! | |
| 415 | -- (void)takePhoto:(BOOL)isFront { | |
| 416 | - | |
| 417 | - self.isHandler = YES; | |
| 418 | - AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; | |
| 419 | - if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied) | |
| 420 | - { | |
| 421 | - //无权限 | |
| 422 | - NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; | |
| 423 | - | |
| 424 | - NSString *appName = [infoDictionary objectForKey:@"CFBundleDisplayName"]; | |
| 425 | - if (appName == nil) | |
| 426 | - { | |
| 427 | - appName = @"APP"; | |
| 428 | - } | |
| 429 | -// NSString *errorStr = @"无相机权限,请在设置中启用"; | |
| 430 | - NSString *message = [NSString stringWithFormat:@"请在iPhone的“设置-隐私”选项中,允许%@访问你的相机。", appName]; | |
| 431 | - | |
| 432 | - UIAlertController *actionAlert = [UIAlertController alertControllerWithTitle:@"" message:message preferredStyle:UIAlertControllerStyleAlert]; | |
| 433 | -// UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"去设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { | |
| 434 | -// // 引导去设置 | |
| 435 | -// NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; | |
| 436 | -// if ([[UIApplication sharedApplication]canOpenURL:url]) { | |
| 437 | -// [[UIApplication sharedApplication]openURL:url]; | |
| 438 | -// } | |
| 439 | -// }]; | |
| 440 | - UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleCancel handler:NULL]; | |
| 441 | - [actionAlert addAction:action2]; | |
| 442 | -// [actionAlert addAction:action1]; | |
| 443 | - [self presentViewController:actionAlert animated:YES completion:nil]; | |
| 444 | - | |
| 445 | -// [QMUITips showError:errorStr inView:self.view hideAfterDelay:1.5f]; | |
| 446 | - return; | |
| 447 | - } | |
| 448 | - | |
| 449 | - if (isFront) { | |
| 450 | - _isFont = YES; | |
| 451 | - UIViewController * vc = | |
| 452 | - [AipCaptureCardVC ViewControllerWithCardType:CardTypeIdCardFont | |
| 453 | - andImageHandler:^(UIImage *image) { | |
| 454 | - | |
| 455 | - self.fontImage = image; | |
| 456 | - [[AipOcrService shardService] detectIdCardFrontFromImage:image | |
| 457 | - withOptions:nil | |
| 458 | - successHandler:_successHandler | |
| 459 | - failHandler:_failHandler]; | |
| 460 | - }]; | |
| 461 | - | |
| 462 | - [self presentViewController:vc animated:YES completion:nil]; | |
| 463 | - | |
| 464 | - } else if (!isFront) { | |
| 465 | - | |
| 466 | - _isFont = NO; | |
| 467 | - UIViewController * vc = | |
| 468 | - [AipCaptureCardVC ViewControllerWithCardType:CardTypeIdCardBack | |
| 469 | - andImageHandler:^(UIImage *image) { | |
| 470 | - | |
| 471 | - self.backImage = image; | |
| 472 | - [[AipOcrService shardService] detectIdCardBackFromImage:image | |
| 473 | - withOptions:nil | |
| 474 | - successHandler:_successHandler | |
| 475 | - failHandler:_failHandler]; | |
| 476 | - }]; | |
| 477 | - [self presentViewController:vc animated:YES completion:nil]; | |
| 478 | - } | |
| 479 | -} | |
| 480 | - | |
| 481 | 396 | #pragma mark - |
| 482 | -#pragma mark - 提交 Action !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | |
| 397 | +#pragma mark - 提交 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | |
| 483 | 398 | - (void)submit:(UIButton *)sender { |
| 484 | 399 | |
| 485 | 400 | sender.selected = !sender.selected; |
| ... | ... | @@ -574,23 +489,7 @@ |
| 574 | 489 | }]; |
| 575 | 490 | } |
| 576 | 491 | |
| 577 | -#pragma mark - Action !!!!!!!!!!!!!!!!!!! | |
| 578 | -- (void)backAction | |
| 579 | -{ | |
| 580 | -// if (self.delegate && [self.delegate respondsToSelector:@selector(completeRefresh)]) { | |
| 581 | -// [self.delegate completeRefresh]; | |
| 582 | -// } | |
| 583 | -// [[AppDelegate sharedAppDelegate] popToRootViewController]; | |
| 584 | - [self.navigationController popViewControllerAnimated:YES]; | |
| 585 | -} | |
| 586 | - | |
| 587 | -- (BOOL)shouldPopViewControllerByBackButtonOrPopGesture:(BOOL)byPopGesture { | |
| 588 | - | |
| 589 | - [self backAction]; | |
| 590 | - return NO; | |
| 591 | -} | |
| 592 | - | |
| 593 | -#pragma mark - Image 转 Data !!!!!!!!!!!!!!!!!!!!!!!!!!!! | |
| 492 | +// Image 转 Data | |
| 594 | 493 | - (NSData *)imageDatasWithImage:(UIImage *)image { |
| 595 | 494 | |
| 596 | 495 | NSData *imageData; |
| ... | ... | @@ -602,82 +501,105 @@ |
| 602 | 501 | return imageData; |
| 603 | 502 | } |
| 604 | 503 | |
| 605 | -#pragma mark - UITableViewDataSource | |
| 606 | -- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { | |
| 607 | - return 1; | |
| 608 | -} | |
| 609 | - | |
| 610 | -- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { | |
| 611 | - return self.dataArray.count+1; | |
| 612 | -} | |
| 613 | - | |
| 614 | -- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | |
| 504 | +#pragma mark - 调用百度SDK识别 !!!!!!!!!!!!!!!! | |
| 505 | +- (void)goToBaiDuOrcController:(BOOL)isFront { | |
| 615 | 506 | |
| 616 | - if (indexPath.row < self.dataArray.count) { | |
| 617 | - AgreementModel *model = self.dataArray[indexPath.row]; | |
| 618 | - NSString *shootCellId = [NSString stringWithFormat:@"%zd",indexPath.row]; | |
| 619 | - ApplyForShootCell *cell = [tableView dequeueReusableCellWithIdentifier:shootCellId]; | |
| 620 | - if (!cell) { | |
| 621 | - cell = [[ApplyForShootCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:shootCellId]; | |
| 622 | - cell.model = model; | |
| 623 | - cell.selectionStyle = UITableViewCellSelectionStyleNone; | |
| 624 | - } | |
| 625 | - __weak __typeof(self)weakSelf = self; | |
| 626 | - cell.clickShootBtnBlock = ^() { | |
| 627 | - if (model.isOwn) { | |
| 628 | - //拍照||相册 | |
| 629 | - [weakSelf iconAction]; | |
| 630 | - } else { | |
| 631 | - //身份证 | |
| 632 | - [weakSelf takePhoto:model.isFront]; | |
| 633 | - } | |
| 634 | - }; | |
| 635 | - return cell; | |
| 507 | + self.isHandler = YES; | |
| 508 | + AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; | |
| 509 | + if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied) | |
| 510 | + { | |
| 511 | + //无权限 | |
| 512 | + NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; | |
| 636 | 513 | |
| 637 | - } else { | |
| 638 | - NSString *confirmCellId = [NSString stringWithFormat:@"%zd",indexPath.row]; | |
| 639 | - ApplyForConfirmCell *cell = [tableView dequeueReusableCellWithIdentifier:confirmCellId]; | |
| 640 | - if (!cell) { | |
| 641 | - cell = [[ApplyForConfirmCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:confirmCellId]; | |
| 514 | + NSString *appName = [infoDictionary objectForKey:@"CFBundleDisplayName"]; | |
| 515 | + if (appName == nil) | |
| 516 | + { | |
| 517 | + appName = @"APP"; | |
| 642 | 518 | } |
| 643 | - cell.selectionStyle = UITableViewCellSelectionStyleNone; | |
| 644 | - AgreementModel *model = [[AgreementModel alloc] init]; | |
| 645 | - model.confirmTitle = @"下一步"; | |
| 646 | - cell.model = model; | |
| 647 | - __weak __typeof(self)weakSelf = self; | |
| 648 | - cell.clickBtnBlock = ^(UIButton *btn){ | |
| 649 | - [weakSelf submit:btn]; | |
| 650 | - }; | |
| 651 | - self.confirmCell = cell; | |
| 652 | - return cell; | |
| 653 | - } | |
| 519 | +// NSString *errorStr = @"无相机权限,请在设置中启用"; | |
| 520 | + NSString *message = [NSString stringWithFormat:@"请在iPhone的“设置-隐私”选项中,允许%@访问你的相机。", appName]; | |
| 521 | + | |
| 522 | + UIAlertController *actionAlert = [UIAlertController alertControllerWithTitle:@"" message:message preferredStyle:UIAlertControllerStyleAlert]; | |
| 523 | +// UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"去设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { | |
| 524 | +// // 引导去设置 | |
| 525 | +// NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; | |
| 526 | +// if ([[UIApplication sharedApplication]canOpenURL:url]) { | |
| 527 | +// [[UIApplication sharedApplication]openURL:url]; | |
| 528 | +// } | |
| 529 | +// }]; | |
| 530 | + UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleCancel handler:NULL]; | |
| 531 | + [actionAlert addAction:action2]; | |
| 532 | +// [actionAlert addAction:action1]; | |
| 533 | + [self presentViewController:actionAlert animated:YES completion:nil]; | |
| 654 | 534 | |
| 535 | +// [QMUITips showError:errorStr inView:self.view hideAfterDelay:1.5f]; | |
| 536 | + return; | |
| 537 | + } | |
| 538 | + | |
| 539 | + if (isFront) { | |
| 540 | + _isFont = YES; | |
| 541 | + UIViewController * vc = | |
| 542 | + [AipCaptureCardVC ViewControllerWithCardType:CardTypeIdCardFont | |
| 543 | + andImageHandler:^(UIImage *image) { | |
| 544 | + | |
| 545 | + self.fontImage = image; | |
| 546 | + [[AipOcrService shardService] detectIdCardFrontFromImage:image | |
| 547 | + withOptions:nil | |
| 548 | + successHandler:_successHandler | |
| 549 | + failHandler:_failHandler]; | |
| 550 | + }]; | |
| 551 | + | |
| 552 | + [self presentViewController:vc animated:YES completion:nil]; | |
| 553 | + | |
| 554 | + } else if (!isFront) { | |
| 555 | + | |
| 556 | + _isFont = NO; | |
| 557 | + UIViewController * vc = | |
| 558 | + [AipCaptureCardVC ViewControllerWithCardType:CardTypeIdCardBack | |
| 559 | + andImageHandler:^(UIImage *image) { | |
| 560 | + | |
| 561 | + self.backImage = image; | |
| 562 | + [[AipOcrService shardService] detectIdCardBackFromImage:image | |
| 563 | + withOptions:nil | |
| 564 | + successHandler:_successHandler | |
| 565 | + failHandler:_failHandler]; | |
| 566 | + }]; | |
| 567 | + [self presentViewController:vc animated:YES completion:nil]; | |
| 568 | + } | |
| 655 | 569 | } |
| 656 | 570 | |
| 657 | -- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { | |
| 658 | - if (indexPath.row < self.dataArray.count) { | |
| 659 | - if (indexPath.row == 2) { | |
| 660 | - return 299; | |
| 571 | +// 自拍cell点击事件 | |
| 572 | +- (void)clickedIconImageAction { | |
| 573 | + AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; | |
| 574 | + if ((authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied) && iOS7Later) { | |
| 575 | + // 无权限 做一个友好的提示 | |
| 576 | + [self goPrivacySetting]; | |
| 577 | + } else if (authStatus == AVAuthorizationStatusNotDetermined) { | |
| 578 | + // fix issue 466, 防止用户首次拍照拒绝授权时相机页黑屏 | |
| 579 | + if (iOS7Later) { | |
| 580 | + [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { | |
| 581 | + if (granted) { | |
| 582 | + dispatch_sync(dispatch_get_main_queue(), ^{ | |
| 583 | + [self showBottomSelectView]; | |
| 584 | + }); | |
| 585 | + } | |
| 586 | + }]; | |
| 661 | 587 | } else { |
| 662 | - return 256; | |
| 588 | + [self showBottomSelectView]; | |
| 663 | 589 | } |
| 664 | 590 | } else { |
| 665 | - if (kNavigationBarHeight+256*2+145<KScreenHeight) { | |
| 666 | - return KScreenHeight-kNavigationBarHeight-256*2; | |
| 667 | - } else { | |
| 668 | - return 145; | |
| 669 | - } | |
| 591 | + [self showBottomSelectView]; | |
| 670 | 592 | } |
| 671 | 593 | } |
| 672 | 594 | |
| 673 | -#pragma mark - 自拍 | |
| 674 | --(void)photoBtnClick { | |
| 595 | +#pragma mark - 显示下方选择拍照/相册视图 | |
| 596 | +-(void)showBottomSelectView { | |
| 675 | 597 | |
| 676 | 598 | __weak __typeof(self)weakSelf = self; |
| 677 | 599 | [self.view createAlertViewTitleArray:@[@"拍照",@"从手机相册选择"] subTitleArr:@[@"",@""] textColor:RGBA(76, 170, 252, 1) subTitleColor:[UIColor whiteColor] firstFont:UIFontMake(18.0f) font:UIFontMake(18.0f) subFont:UIFontMake(18.0f) cancelTitle:@"取消" cancelFont:UIFontMake(18.0f) cancelTitleColor:UIColorMake(102, 102, 102) actionBlock:^(UIButton *button, NSInteger didRow) { |
| 678 | 600 | switch (didRow) { |
| 679 | 601 | case 0:{ |
| 680 | - [weakSelf takeToXFPhoto]; | |
| 602 | + [weakSelf pushXTPhoto]; | |
| 681 | 603 | } |
| 682 | 604 | break; |
| 683 | 605 | case 1:{ |
| ... | ... | @@ -690,8 +612,8 @@ |
| 690 | 612 | }]; |
| 691 | 613 | } |
| 692 | 614 | |
| 693 | -#pragma mark - 跳转到相机 | |
| 694 | --(void)takeToXFPhoto { | |
| 615 | +#pragma mark - 跳转到系统相机 | |
| 616 | +-(void)pushXTPhoto { | |
| 695 | 617 | if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { |
| 696 | 618 | self.pickerVC.sourceType = UIImagePickerControllerSourceTypeCamera; |
| 697 | 619 | //设置拍照后的图片可被编辑 |
| ... | ... | @@ -772,29 +694,6 @@ |
| 772 | 694 | [picker dismissViewControllerAnimated:YES completion:^{}]; |
| 773 | 695 | } |
| 774 | 696 | |
| 775 | -// 自拍cell点击事件 | |
| 776 | -- (void)iconAction { | |
| 777 | - AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; | |
| 778 | - if ((authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied) && iOS7Later) { | |
| 779 | - // 无权限 做一个友好的提示 | |
| 780 | - [self goPrivacySetting]; | |
| 781 | - } else if (authStatus == AVAuthorizationStatusNotDetermined) { | |
| 782 | - // fix issue 466, 防止用户首次拍照拒绝授权时相机页黑屏 | |
| 783 | - if (iOS7Later) { | |
| 784 | - [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { | |
| 785 | - if (granted) { | |
| 786 | - dispatch_sync(dispatch_get_main_queue(), ^{ | |
| 787 | - [self photoBtnClick]; | |
| 788 | - }); | |
| 789 | - } | |
| 790 | - }]; | |
| 791 | - } else { | |
| 792 | - [self photoBtnClick]; | |
| 793 | - } | |
| 794 | - } else { | |
| 795 | - [self photoBtnClick]; | |
| 796 | - } | |
| 797 | -} | |
| 798 | 697 | // 隐私设置提醒 |
| 799 | 698 | - (void)goPrivacySetting { |
| 800 | 699 | dispatch_async(dispatch_get_main_queue(), ^{ |
| ... | ... | @@ -811,7 +710,7 @@ |
| 811 | 710 | }); |
| 812 | 711 | } |
| 813 | 712 | |
| 814 | -#pragma maek -从相册选择 | |
| 713 | +#pragma mark - 从相册选择 | |
| 815 | 714 | - (void)pushTZImagePickerController { |
| 816 | 715 | __weak typeof(self)weakSelf = self; |
| 817 | 716 | TZImagePickerController *picker = [[TZImagePickerController alloc]initWithMaxImagesCount:1 delegate:self]; |
| ... | ... | @@ -836,38 +735,130 @@ |
| 836 | 735 | [self presentViewController:picker animated:YES completion:nil]; |
| 837 | 736 | } |
| 838 | 737 | |
| 839 | -#pragma mark UIAlertViewDelegate | |
| 840 | -- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { | |
| 841 | - [self dismissViewControllerAnimated:YES completion:nil]; | |
| 738 | +#pragma mark - IDCardAuthAlertViewDelegate | |
| 739 | +- (void)IDCardAlertView:(CNLiveIDCardAuthAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { | |
| 740 | + | |
| 741 | + [alertView removeFromSuperview]; | |
| 742 | + alertView = nil; | |
| 743 | +} | |
| 744 | + | |
| 745 | +#pragma mark - 加载页面数据 !!!!!!!!!!!!!!!!! | |
| 746 | +- (void)loadData { | |
| 747 | + | |
| 748 | + NSArray *array = @[ | |
| 749 | + @{ | |
| 750 | + @"shootTitle":@"第一步", | |
| 751 | + @"shootImage":@"observer_idcard_front", | |
| 752 | + @"isFront":@"1", | |
| 753 | + @"isOwn":@"0" | |
| 754 | + }, | |
| 755 | + @{ | |
| 756 | + @"shootTitle":@"第二步", | |
| 757 | + @"shootImage":@"observer_idcard_back", | |
| 758 | + @"isFront":@"0", | |
| 759 | + @"isOwn":@"0" | |
| 760 | + }, | |
| 761 | + @{ | |
| 762 | + @"shootTitle":@"第三步", | |
| 763 | + @"shootImage":@"observer_idcard_own", | |
| 764 | + @"isFront":@"0", | |
| 765 | + @"isOwn":@"1" | |
| 766 | + }, | |
| 767 | + ]; | |
| 768 | + NSMutableArray *arrayM = [NSMutableArray array]; | |
| 769 | + for (NSDictionary *dic in array) { | |
| 770 | + AgreementModel *model = [AgreementModel mj_objectWithKeyValues:dic]; | |
| 771 | + [arrayM addObject:model]; | |
| 772 | + } | |
| 773 | + self.dataArray = arrayM.copy; | |
| 774 | + [self.tableView reloadData]; | |
| 775 | + | |
| 842 | 776 | } |
| 843 | 777 | |
| 778 | +#pragma mark - UITableViewDataSource | |
| 779 | +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { | |
| 780 | + return 1; | |
| 781 | +} | |
| 844 | 782 | |
| 845 | -#pragma mark - RunTime | |
| 846 | -- (void)mockBundlerIdForTest { | |
| 847 | -#pragma clang diagnostic push | |
| 848 | -#pragma clang diagnostic ignored "-Wundeclared-selector" | |
| 849 | - [self mockClass:[NSBundle class] originalFunction:@selector(bundleIdentifier) swizzledFunction:@selector(sapicamera_bundleIdentifier)]; | |
| 850 | -#pragma clang diagnostic pop | |
| 783 | +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { | |
| 784 | + return self.dataArray.count+1; | |
| 851 | 785 | } |
| 852 | 786 | |
| 853 | -- (void)mockClass:(Class)class originalFunction:(SEL)originalSelector swizzledFunction:(SEL)swizzledSelector { | |
| 854 | - | |
| 855 | - Method originalMethod = class_getInstanceMethod(class, originalSelector); | |
| 856 | - Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector); | |
| 857 | - | |
| 858 | - BOOL didAddMethod = class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod)); | |
| 787 | +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | |
| 859 | 788 | |
| 860 | - if (didAddMethod) { | |
| 861 | - class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod)); | |
| 789 | + if (indexPath.row < self.dataArray.count) { | |
| 790 | + AgreementModel *model = self.dataArray[indexPath.row]; | |
| 791 | + NSString *shootCellId = [NSString stringWithFormat:@"%zd",indexPath.row]; | |
| 792 | + ApplyForShootCell *cell = [tableView dequeueReusableCellWithIdentifier:shootCellId]; | |
| 793 | + if (!cell) { | |
| 794 | + cell = [[ApplyForShootCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:shootCellId]; | |
| 795 | + cell.model = model; | |
| 796 | + cell.selectionStyle = UITableViewCellSelectionStyleNone; | |
| 797 | + } | |
| 798 | + __weak __typeof(self)weakSelf = self; | |
| 799 | + cell.clickShootBtnBlock = ^() { | |
| 800 | + if (model.isOwn) { | |
| 801 | + //自拍cell点击事件 | |
| 802 | + [weakSelf clickedIconImageAction]; | |
| 803 | + } else { | |
| 804 | + //身份证 | |
| 805 | + [weakSelf goToBaiDuOrcController:model.isFront]; | |
| 806 | + } | |
| 807 | + }; | |
| 808 | + return cell; | |
| 809 | + | |
| 862 | 810 | } else { |
| 863 | - method_exchangeImplementations(originalMethod, swizzledMethod); | |
| 811 | + NSString *confirmCellId = [NSString stringWithFormat:@"%zd",indexPath.row]; | |
| 812 | + ApplyForConfirmCell *cell = [tableView dequeueReusableCellWithIdentifier:confirmCellId]; | |
| 813 | + if (!cell) { | |
| 814 | + cell = [[ApplyForConfirmCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:confirmCellId]; | |
| 815 | + } | |
| 816 | + cell.selectionStyle = UITableViewCellSelectionStyleNone; | |
| 817 | + AgreementModel *model = [[AgreementModel alloc] init]; | |
| 818 | + model.confirmTitle = @"下一步"; | |
| 819 | + cell.model = model; | |
| 820 | + __weak __typeof(self)weakSelf = self; | |
| 821 | + cell.clickBtnBlock = ^(UIButton *btn){ | |
| 822 | + [weakSelf submit:btn]; | |
| 823 | + }; | |
| 824 | + self.confirmCell = cell; | |
| 825 | + return cell; | |
| 826 | + } | |
| 827 | + | |
| 828 | +} | |
| 829 | + | |
| 830 | +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { | |
| 831 | + if (indexPath.row < self.dataArray.count) { | |
| 832 | + if (indexPath.row == 2) { | |
| 833 | + return 299; | |
| 834 | + } else { | |
| 835 | + return 256; | |
| 836 | + } | |
| 837 | + } else { | |
| 838 | + if (kNavigationBarHeight+256*2+145<KScreenHeight) { | |
| 839 | + return KScreenHeight-kNavigationBarHeight-256*2; | |
| 840 | + } else { | |
| 841 | + return 145; | |
| 842 | + } | |
| 864 | 843 | } |
| 844 | +} | |
| 845 | + | |
| 846 | +#pragma mark - 返回 !!!!!!!!!!!!!!!!!!! | |
| 847 | +- (void)backAction | |
| 848 | +{ | |
| 849 | + [self.navigationController popViewControllerAnimated:YES]; | |
| 850 | +} | |
| 851 | + | |
| 852 | +- (BOOL)shouldPopViewControllerByBackButtonOrPopGesture:(BOOL)byPopGesture { | |
| 865 | 853 | |
| 854 | + [self backAction]; | |
| 855 | + return NO; | |
| 866 | 856 | } |
| 857 | + | |
| 867 | 858 | #pragma mark - SubViews |
| 868 | 859 | -(UITableView *)tableView { |
| 869 | 860 | if (!_tableView) { |
| 870 | - _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight) style:UITableViewStylePlain]; | |
| 861 | + _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight-kNavigationBarHeight) style:UITableViewStylePlain]; | |
| 871 | 862 | _tableView.backgroundColor = RGB(242, 242, 242); |
| 872 | 863 | _tableView.delegate = self; |
| 873 | 864 | _tableView.dataSource = self; |
| ... | ... | @@ -878,49 +869,8 @@ |
| 878 | 869 | return _tableView; |
| 879 | 870 | } |
| 880 | 871 | |
| 881 | -- (void)didReceiveMemoryWarning { | |
| 882 | - [super didReceiveMemoryWarning]; | |
| 883 | - // Dispose of any resources that can be recreated. | |
| 884 | -} | |
| 885 | - | |
| 886 | 872 | - (void)dealloc { |
| 887 | 873 | NSLog(@"dealloc ==> ApplyForShootController"); |
| 888 | 874 | } |
| 889 | 875 | |
| 890 | -// 字典转json字符串方法 | |
| 891 | - | |
| 892 | -- (NSString *)convertToJsonData:(NSDictionary *)dict | |
| 893 | -{ | |
| 894 | - NSError *error; | |
| 895 | - NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error]; | |
| 896 | - | |
| 897 | - NSString *jsonString; | |
| 898 | - if (!jsonData) { | |
| 899 | - NSLog(@"%@",error); | |
| 900 | - }else{ | |
| 901 | - jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding]; | |
| 902 | - } | |
| 903 | - | |
| 904 | - NSMutableString *mutStr = [NSMutableString stringWithString:jsonString]; | |
| 905 | - NSRange range = {0,jsonString.length}; | |
| 906 | - //去掉字符串中的空格 | |
| 907 | - [mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range]; | |
| 908 | - | |
| 909 | - NSRange range2 = {0,mutStr.length}; | |
| 910 | - //去掉字符串中的换行符 | |
| 911 | - [mutStr replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:range2]; | |
| 912 | - return mutStr; | |
| 913 | - | |
| 914 | -} | |
| 915 | - | |
| 916 | -/* | |
| 917 | -#pragma mark - Navigation | |
| 918 | - | |
| 919 | -// In a storyboard-based application, you will often want to do a little preparation before navigation | |
| 920 | -- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { | |
| 921 | - // Get the new view controller using [segue destinationViewController]. | |
| 922 | - // Pass the selected object to the new view controller. | |
| 923 | -} | |
| 924 | -*/ | |
| 925 | - | |
| 926 | 876 | @end | ... | ... |
CNLiveBPersonalVerificationModule/Classes/CNBPersonCardInfo/View/CNLiveIDCardAuthAlertView.h
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveIDCardAuthAlertView.h | |
| 3 | +// CNLiveBPersonalVerificationModule | |
| 4 | +// | |
| 5 | +// Created by cnliveJunBo on 2020/4/24. | |
| 6 | +// | |
| 7 | + | |
| 8 | +#import <UIKit/UIKit.h> | |
| 9 | +@class CNLiveIDCardAuthAlertView; | |
| 10 | +NS_ASSUME_NONNULL_BEGIN | |
| 11 | + | |
| 12 | +@protocol IDCardAuthAlertViewDelegate <NSObject> | |
| 13 | +@optional | |
| 14 | +- (void)IDCardAlertView:(CNLiveIDCardAuthAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex; | |
| 15 | + | |
| 16 | +@end | |
| 17 | + | |
| 18 | +@interface CNLiveIDCardAuthAlertView : UIView | |
| 19 | + | |
| 20 | +@property (nonatomic, assign) BOOL messageLabTextAlignmentLeft; | |
| 21 | + | |
| 22 | +- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate; | |
| 23 | + | |
| 24 | +- (void)show; | |
| 25 | + | |
| 26 | +@end | |
| 27 | + | |
| 28 | +NS_ASSUME_NONNULL_END | ... | ... |
CNLiveBPersonalVerificationModule/Classes/CNBPersonCardInfo/View/CNLiveIDCardAuthAlertView.m
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveIDCardAuthAlertView.m | |
| 3 | +// CNLiveBPersonalVerificationModule | |
| 4 | +// | |
| 5 | +// Created by cnliveJunBo on 2020/4/24. | |
| 6 | +// | |
| 7 | + | |
| 8 | +#import "CNLiveIDCardAuthAlertView.h" | |
| 9 | +#import <CNLiveBaseKit/CNLiveBaseKit.h> | |
| 10 | +#import <Masonry/Masonry.h> | |
| 11 | + | |
| 12 | +@interface CNLiveIDCardAuthAlertView () | |
| 13 | + | |
| 14 | +@property (nonatomic, strong) UIView *contentBgView; | |
| 15 | +@property (nonatomic, strong) UILabel *titleLab; | |
| 16 | +@property (nonatomic, strong) UIView *messageBgView; | |
| 17 | +@property (nonatomic, strong) UILabel *messageLab; | |
| 18 | +@property (nonatomic, strong) UIView *horizontalLine;//水平 | |
| 19 | +@property (nonatomic, strong) UIView *verticalLine;//垂直 | |
| 20 | +@property (nonatomic, strong) UIButton *confirmBtn; | |
| 21 | +@property (nonatomic, strong) UIButton *cancelBtn; | |
| 22 | + | |
| 23 | +@property (nonatomic, copy) NSString *title; | |
| 24 | +@property (nonatomic, copy) NSString *message; | |
| 25 | + | |
| 26 | +@property (nonatomic, weak) id <IDCardAuthAlertViewDelegate>delegate; | |
| 27 | + | |
| 28 | +@end | |
| 29 | + | |
| 30 | +@implementation CNLiveIDCardAuthAlertView | |
| 31 | + | |
| 32 | +- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate | |
| 33 | +{ | |
| 34 | + self = [super init]; | |
| 35 | + if (self) { | |
| 36 | + self.title = title; | |
| 37 | + self.message = message; | |
| 38 | + self.delegate = delegate; | |
| 39 | + [self setupUI]; | |
| 40 | + } | |
| 41 | + return self; | |
| 42 | +} | |
| 43 | + | |
| 44 | +- (void)show { | |
| 45 | + | |
| 46 | + [[UIApplication sharedApplication].delegate.window addSubview:self]; | |
| 47 | +} | |
| 48 | + | |
| 49 | +- (void)setMessageLabTextAlignmentLeft:(BOOL)messageLabTextAlignmentLeft { | |
| 50 | + _messageLabTextAlignmentLeft = messageLabTextAlignmentLeft; | |
| 51 | + | |
| 52 | + _messageLab.textAlignment = NSTextAlignmentLeft; | |
| 53 | +} | |
| 54 | + | |
| 55 | +- (void)setupUI { | |
| 56 | + | |
| 57 | + self.backgroundColor = RGBA(51, 51, 51, 0.5); | |
| 58 | + self.frame = [UIScreen mainScreen].bounds; | |
| 59 | + [self addSubview:self.contentBgView]; | |
| 60 | + [self.contentBgView addSubview:self.titleLab]; | |
| 61 | + [self.contentBgView addSubview:self.messageBgView]; | |
| 62 | + [self.messageBgView addSubview:self.messageLab]; | |
| 63 | + [self.contentBgView addSubview:self.horizontalLine]; | |
| 64 | + [self.contentBgView addSubview:self.verticalLine]; | |
| 65 | + [self.contentBgView addSubview:self.confirmBtn]; | |
| 66 | + [self.contentBgView addSubview:self.cancelBtn]; | |
| 67 | + | |
| 68 | + [self.contentBgView mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 69 | + make.top.equalTo(self).offset(200+kStatusHeight); | |
| 70 | + make.left.equalTo(self).offset(52.5); | |
| 71 | + make.right.equalTo(self).offset(-52.5); | |
| 72 | + }]; | |
| 73 | + [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 74 | + make.top.equalTo(self.contentBgView).offset(16); | |
| 75 | + make.centerX.equalTo(self.contentBgView); | |
| 76 | + }]; | |
| 77 | + [self.messageBgView mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 78 | + make.top.equalTo(self.titleLab.mas_bottom).offset(11); | |
| 79 | + make.left.equalTo(self.contentBgView).offset(20.5); | |
| 80 | + make.right.equalTo(self.contentBgView).offset(-20.5); | |
| 81 | + make.height.mas_greaterThanOrEqualTo(30); | |
| 82 | + }]; | |
| 83 | + [self.messageLab mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 84 | + make.top.left.equalTo(self.messageBgView).offset(12); | |
| 85 | + make.bottom.right.equalTo(self.messageBgView).offset(-12); | |
| 86 | + }]; | |
| 87 | + [self.horizontalLine mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 88 | + make.top.equalTo(self.messageBgView.mas_bottom).offset(11); | |
| 89 | + make.left.right.equalTo(self.contentBgView); | |
| 90 | + make.height.mas_equalTo(0.5); | |
| 91 | + }]; | |
| 92 | + [self.verticalLine mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 93 | + make.top.equalTo(self.horizontalLine.mas_bottom); | |
| 94 | + make.centerX.equalTo(self.horizontalLine); | |
| 95 | + make.width.mas_equalTo(0.5); | |
| 96 | + make.height.mas_equalTo(44); | |
| 97 | + }]; | |
| 98 | + [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 99 | + make.top.equalTo(self.horizontalLine.mas_bottom); | |
| 100 | + make.left.equalTo(self.contentBgView); | |
| 101 | + make.right.equalTo(self.verticalLine.mas_left); | |
| 102 | + make.height.mas_equalTo(44); | |
| 103 | + make.bottom.equalTo(self.contentBgView); | |
| 104 | + }]; | |
| 105 | + [self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 106 | + make.top.equalTo(self.horizontalLine.mas_bottom); | |
| 107 | + make.left.equalTo(self.verticalLine.mas_right); | |
| 108 | + make.right.equalTo(self.contentBgView); | |
| 109 | + make.height.mas_equalTo(44); | |
| 110 | + }]; | |
| 111 | + | |
| 112 | +} | |
| 113 | + | |
| 114 | +#pragma mark - Action | |
| 115 | +- (void)confirmBtnAction:(UIButton *)sender { | |
| 116 | + | |
| 117 | + [self clickedButtonAtIndex:1]; | |
| 118 | +} | |
| 119 | + | |
| 120 | +- (void)cancelBtnAction:(UIButton *)sender { | |
| 121 | + | |
| 122 | + [self clickedButtonAtIndex:0]; | |
| 123 | +} | |
| 124 | + | |
| 125 | +- (void)clickedButtonAtIndex:(NSInteger)index { | |
| 126 | + | |
| 127 | + if (self.delegate && [self.delegate respondsToSelector:@selector(IDCardAlertView:clickedButtonAtIndex:)]) { | |
| 128 | + [self.delegate IDCardAlertView:self clickedButtonAtIndex:index]; | |
| 129 | + } | |
| 130 | +} | |
| 131 | + | |
| 132 | +#pragma mark - Getter | |
| 133 | +- (UIView *)contentBgView { | |
| 134 | + if (!_contentBgView) { | |
| 135 | + _contentBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; | |
| 136 | + _contentBgView.backgroundColor = kWhiteColor; | |
| 137 | + _contentBgView.layer.cornerRadius = 5; | |
| 138 | + _contentBgView.layer.masksToBounds = YES; | |
| 139 | + } | |
| 140 | + return _contentBgView; | |
| 141 | +} | |
| 142 | + | |
| 143 | +- (UILabel *)titleLab { | |
| 144 | + if (!_titleLab) { | |
| 145 | + _titleLab = [[UILabel alloc] init]; | |
| 146 | + _titleLab.text = self.title; | |
| 147 | + _titleLab.textColor = KBlack51Color; | |
| 148 | + _titleLab.font = [UIFont fontWithName:@"PingFangSC-Medium" size:15]; | |
| 149 | + } | |
| 150 | + return _titleLab; | |
| 151 | +} | |
| 152 | + | |
| 153 | +- (UIView *)messageBgView { | |
| 154 | + if (!_messageBgView) { | |
| 155 | + _messageBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 90)]; | |
| 156 | + _messageBgView.backgroundColor = RGBA(244, 244, 244, 1); | |
| 157 | + _messageBgView.layer.cornerRadius = 5; | |
| 158 | + _messageBgView.layer.masksToBounds = YES; | |
| 159 | + } | |
| 160 | + return _messageBgView; | |
| 161 | +} | |
| 162 | + | |
| 163 | +- (UILabel *)messageLab { | |
| 164 | + if (!_messageLab) { | |
| 165 | + _messageLab = [[UILabel alloc] init]; | |
| 166 | + NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:self.message]; | |
| 167 | + NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; | |
| 168 | + paragraphStyle.lineSpacing = 6.0; // 设置行间距 | |
| 169 | + [attributedStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attributedStr.length)]; | |
| 170 | + _messageLab.attributedText = attributedStr; | |
| 171 | + _messageLab.textColor = RGBA(102, 102, 102, 1); | |
| 172 | + _messageLab.font = [UIFont fontWithName:@"PingFangSC-Medium" size:12]; | |
| 173 | + _messageLab.numberOfLines = 0; | |
| 174 | + _messageLab.textAlignment = NSTextAlignmentCenter; | |
| 175 | + } | |
| 176 | + return _messageLab; | |
| 177 | +} | |
| 178 | + | |
| 179 | +- (UIButton *)confirmBtn { | |
| 180 | + if (!_confirmBtn) { | |
| 181 | + _confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom]; | |
| 182 | + [_confirmBtn setTitle:@"确定" forState:UIControlStateNormal]; | |
| 183 | + [_confirmBtn setTitleColor:RGBA(72, 167, 249, 1) forState:UIControlStateNormal]; | |
| 184 | + _confirmBtn.titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Bold" size:17]; | |
| 185 | + [_confirmBtn addTarget:self action:@selector(confirmBtnAction:) forControlEvents:UIControlEventTouchUpInside]; | |
| 186 | + } | |
| 187 | + return _confirmBtn; | |
| 188 | +} | |
| 189 | + | |
| 190 | +- (UIButton *)cancelBtn { | |
| 191 | + if (!_cancelBtn) { | |
| 192 | + _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom]; | |
| 193 | + [_cancelBtn setTitle:@"取消" forState:UIControlStateNormal]; | |
| 194 | + [_cancelBtn setTitleColor:KGray153Color forState:UIControlStateNormal]; | |
| 195 | + _cancelBtn.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:17]; | |
| 196 | + [_cancelBtn addTarget:self action:@selector(cancelBtnAction:) forControlEvents:UIControlEventTouchUpInside]; | |
| 197 | + } | |
| 198 | + return _cancelBtn; | |
| 199 | +} | |
| 200 | + | |
| 201 | +- (UIView *)horizontalLine { | |
| 202 | + if (!_horizontalLine) { | |
| 203 | + _horizontalLine = [[UIView alloc] init]; | |
| 204 | + _horizontalLine.backgroundColor = RGBA(199, 197, 199, 1); | |
| 205 | + _horizontalLine.layer.borderColor = RGBA(199, 197, 199, 1).CGColor; | |
| 206 | + } | |
| 207 | + return _horizontalLine; | |
| 208 | +} | |
| 209 | + | |
| 210 | +- (UIView *)verticalLine { | |
| 211 | + if (!_verticalLine) { | |
| 212 | + _verticalLine = [[UIView alloc] init]; | |
| 213 | + _verticalLine.backgroundColor = RGBA(199, 197, 199, 1); | |
| 214 | + _verticalLine.layer.borderColor = RGBA(199, 197, 199, 1).CGColor; | |
| 215 | + } | |
| 216 | + return _verticalLine; | |
| 217 | +} | |
| 218 | + | |
| 219 | +@end | ... | ... |