// // LCCameraAduitVC.m // LiveChat // // Created by 张灿 on 2018/8/31. // Copyright © 2018年 caicai. All rights reserved. // #import "YOUPAILCCameraAuditVC.h" #import "YOUPAILCUploadCameraAuditVC.h" @interface YOUPAILCCameraAuditVC () @property(nonatomic,strong)NSString* youpaipauthimg;//认证的示例图片 @property(nonatomic,assign)NSInteger youpaipstatus;//认证状态 @property(nonatomic,strong)UIScrollView* youpaipscrollView; @property(nonatomic,strong)UIImageView* youpaipauthImgView; @property(nonatomic,strong)UIButton* youpaipopenCameraBtn; @property(nonatomic,strong)NSString* youpaipaction_type; @property(nonatomic,strong)NSString* youpaipaction_image; @property(nonatomic,strong)NSString* youpaipaudit_remark; @property(nonatomic,assign)NSInteger youpaipaudit_status; @end @implementation YOUPAILCCameraAuditVC - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self youpaifinitData]; } - (void)viewDidLoad { [super viewDidLoad]; self.title = @"自拍认证"; [self youpaifsetupView]; } - (void)youpaifinitData{ [LCHttpHelper requestWithURLString:CameraAudit parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) { NSInteger action_type=[[[dict objectForKey:@"data"]objectForKey:@"action_type"]integerValue]; self.youpaipaction_type =[NSString stringWithFormat:@"%zd",action_type] ; self.youpaipaction_image = [[dict objectForKey:@"data"]objectForKey:@"action_image"]; self.youpaipaudit_remark = [[dict objectForKey:@"data"]objectForKey:@"audit_remark"]; self.youpaipaudit_status = [[[dict objectForKey:@"data"]objectForKey:@"audit_status"]integerValue]; [self youpaifupdateView]; } } failure:^(NSError *error) { }]; } - (void)youpaifsetupView{ UIScrollView* scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, NavBarHeight, KScreenWidth, KScreenHeight-NavBarHeight)]; scrollView.contentSize = CGSizeMake(KScreenWidth, KScreenHeight-NavBarHeight+1); scrollView.bounces = YES; scrollView.showsHorizontalScrollIndicator = NO; scrollView.showsVerticalScrollIndicator = NO; self.youpaipscrollView = scrollView; [self.view addSubview:scrollView]; UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(14.0f,25.0f,KScreenWidth-28.0f,427.0f)]; baseView.layer.cornerRadius = 6.0f; baseView.layer.masksToBounds = YES; baseView.backgroundColor = HexColorFromRGB(0x2A2935); [self.youpaipscrollView addSubview:baseView]; UILabel* tipLabel = [[UILabel alloc]initWithFrame:CGRectMake(14.0f,25, 200, 20)]; tipLabel.textAlignment = NSTextAlignmentLeft; tipLabel.textColor = [UIColor whiteColor]; tipLabel.font = [UIFont boldSystemFontOfSize:14]; tipLabel.text = @"温馨提示"; [baseView addSubview:tipLabel]; UILabel* tipLabel1 = [[UILabel alloc]initWithFrame:CGRectMake(14.0f,CGRectGetMaxY(tipLabel.frame) + 8.0f, KScreenWidth-28-28, 17.0f)]; tipLabel1.textAlignment = NSTextAlignmentLeft; tipLabel1.textColor = [UIColor whiteColor]; tipLabel1.font = [UIFont systemFontOfSize:14]; tipLabel1.text = @"1.认证照片必须为本人正面全脸清晰露出照"; [baseView addSubview:tipLabel1]; UILabel* tipLabel2 = [[UILabel alloc]initWithFrame:CGRectMake(14.0f,CGRectGetMaxY(tipLabel1.frame), KScreenWidth-28-28, 17.0f)]; tipLabel2.textAlignment = NSTextAlignmentLeft; tipLabel2.textColor = [UIColor whiteColor]; tipLabel2.font = [UIFont systemFontOfSize:14]; tipLabel2.text = @"2.本照片仅用于认证,官方将对照片保密"; [baseView addSubview:tipLabel2]; UIImageView* authImgView = [[UIImageView alloc]initWithFrame:CGRectMake((baseView.mj_w - 230.0f) / 2.0f, CGRectGetMaxY(tipLabel2.frame) + 25.0f, 230,230)]; authImgView.backgroundColor = LCBkgColor; authImgView.contentMode = UIViewContentModeScaleAspectFill; authImgView.layer.cornerRadius = 5.0; authImgView.layer.masksToBounds = YES; self.youpaipauthImgView = authImgView; [baseView addSubview:authImgView]; UILabel *topLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(authImgView.frame) + 14.0f, baseView.mj_w,15)]; topLabel.textColor = HexColorFromRGB(0x9F9DA5); topLabel.font = [UIFont systemFontOfSize:12]; topLabel.textAlignment = NSTextAlignmentCenter; topLabel.text = @"(请模仿示例动作否则不会通过认证)"; [baseView addSubview:topLabel]; UIButton* openCameraBtn = [[UIButton alloc]initWithFrame:CGRectMake(40.0f, scrollView.mj_h - 77.0f - SafeHeight, KScreenWidth-80.0f,48)]; openCameraBtn.backgroundColor = HexColorFromRGB(0x4F4B5B); openCameraBtn.titleLabel.font = [UIFont systemFontOfSize:17]; [openCameraBtn setTitle:@"马上自拍" forState:(UIControlStateNormal)]; [openCameraBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)]; openCameraBtn.layer.cornerRadius = 24.0; openCameraBtn.layer.masksToBounds = YES; [openCameraBtn addTarget:self action:@selector(openCameraClick) forControlEvents:(UIControlEventTouchUpInside)]; openCameraBtn.userInteractionEnabled = NO; self.youpaipopenCameraBtn = openCameraBtn; [scrollView addSubview:openCameraBtn]; } - (void)youpaifupdateView{ [self.youpaipauthImgView sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.youpaipaction_image]]; if (self.youpaipaudit_status == 0 || self.youpaipaudit_status == 3) { [self.youpaipopenCameraBtn setBackgroundImage:[LCTools ColorImage:self.youpaipopenCameraBtn.mj_size FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:GradientLeftToRight] forState:(UIControlStateNormal)]; self.youpaipopenCameraBtn.userInteractionEnabled = YES; if (self.youpaipaudit_status == 0) { [self.youpaipopenCameraBtn setTitle:@"马上自拍" forState:(UIControlStateNormal)]; }else{ [self.youpaipopenCameraBtn setTitle:@"审核未通过,再次自拍" forState:(UIControlStateNormal)]; } }else{ [self.youpaipopenCameraBtn setBackgroundImage:nil forState:(UIControlStateNormal)]; self.youpaipopenCameraBtn.userInteractionEnabled = NO; if (self.youpaipaudit_status == 1) { [self.youpaipopenCameraBtn setTitle:@"人工审核中..." forState:(UIControlStateNormal)]; }else{ [self.youpaipopenCameraBtn setTitle:@"已通过自拍认证" forState:(UIControlStateNormal)]; } } } - (void)openCameraClick{ [UCAuthorityManager cameraAuthority:^{ UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera; if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) { dispatch_async(dispatch_get_main_queue(), ^{ UIImagePickerController* imgPick = [[UIImagePickerController alloc] init]; imgPick.delegate = self; imgPick.sourceType = sourceType; imgPick.cameraDevice = UIImagePickerControllerCameraDeviceFront; imgPick.modalPresentationStyle = UIModalPresentationOverCurrentContext; imgPick.allowsEditing = YES; imgPick.showsCameraControls = YES; [self presentViewController:imgPick animated:YES completion:nil]; }); } else { NSLog(@"模拟器中无法打开照相机,请在真机中使用"); } } denied:^{ UIAlertController *systemAlert = [UIAlertController alertControllerWithTitle:@"请在iphone的“设置-隐私-相机”选项中,允许APP访问您的相机。" message:nil preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]; [systemAlert addAction:action]; [self presentViewController:systemAlert animated:YES completion:nil]; }]; } - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [picker dismissViewControllerAnimated:YES completion:nil]; NSString *type = [info objectForKey:UIImagePickerControllerMediaType]; if ([type isEqualToString:@"public.image"]) { UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage]; YOUPAILCUploadCameraAuditVC* uploadAudit = [[YOUPAILCUploadCameraAuditVC alloc]init]; uploadAudit.youpaipcameraImage = image; uploadAudit.youpaipauthImgUrl = self.youpaipaction_image; uploadAudit.youpaipaction_type = self.youpaipaction_type; [self.navigationController pushViewController:uploadAudit animated:YES]; } } @end