// // YMAuthenticationCenterViewModel.m // MSYOUPAI // // Created by YoMi on 2024/3/2. // Copyright © 2024 MS. All rights reserved. // #import "YMAuthenticationCenterViewModel.h" @interface YMAuthenticationCenterViewModel () /// 示例照链接 @property (nonatomic, strong, readwrite) NSString *samplePhotoUrl; /// 示例照类型 @property (nonatomic, assign, readwrite) NSInteger samplePhotoType; /// 我的照片 @property (nonatomic, strong, readwrite) UIImage *photo; /// 选中认证照数组 @property (nonatomic, strong, readwrite) NSMutableArray *auditPhotoArray; /// 添加认证照 @property (nonatomic, strong, readwrite) RACSubject *addAuditPhotoSubject; /// 删除认证照 @property (nonatomic, strong, readwrite) RACSubject *deleteAuditPhotoSubject; @end @implementation YMAuthenticationCenterViewModel - (void)ym_initialize{ [super ym_initialize]; self.customNavTitle = @"认证中心"; self.samplePhotoUrl = [self.params stringValueForKey:ParamsUrl defaultValue:@""]; self.samplePhotoType = [self.params integerValueForKey:ParamsSubType defaultValue:1]; if([[self.params allKeys] containsObject:@"photo"]){ self.photo = self.params[@"photo"]; [self.auditPhotoArray addObject:self.photo]; } else { self.photo = nil; } @weakify(self) [[self.addAuditPhotoSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id _Nullable photo) { @strongify(self) [self.auditPhotoArray removeAllObjects]; [self.auditPhotoArray addObject:photo]; }]; [[self.deleteAuditPhotoSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id _Nullable photo) { @strongify(self) [self.auditPhotoArray removeAllObjects]; }]; } - (void)uploadAuthenticationPhotoData{ if (self.auditPhotoArray.count <= 0) { YMTipsPopupView *customView = [[YMTipsPopupView alloc]init]; [customView configutationWithTips:@"请根据“示例动作”进行拍照" TipsAlignment:NSTextAlignmentCenter IsHideTitle:NO IsHideSingleButton:NO]; YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade]; popupView.priority = 999; popupView.cornerRadius = adapt(10); popupView.rectCorners = UIRectCornerAllCorners; popupView.positionStyle = YMPositionStyleCenter; popupView.isHideBg = NO; popupView.bgAlpha = 0.3; @weakify(popupView) customView.buttonBlock = ^(BOOL isConfirm) { @strongify(popupView) [popupView dismissWithStyle:YMDismissStyleFade duration:2.0]; }; [popupView pop]; return; } [ZCHUDHelper showWithStatus:@"上传中..."]; [LCCommonHttp uploadImages:self.auditPhotoArray type:@"audit" succress:^(NSArray *imageArray){ NSDictionary *dict = imageArray.lastObject; if ([[dict objectForKey:@"type"] isEqualToString:@"audit"]) { NSString *str = [dict objectForKey:@"url"]; [LCHttpHelper requestWithURLString:UploadCameraAudit parameters:@{ @"photo":str, @"action_type":@(self.samplePhotoType), } needToken:YES type:HttpRequestTypePost success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { [ZCHUDHelper showTitle:@"照片已提交"]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [[YMGlobalUtils getCurrentVC].navigationController popViewControllerAnimated:YES]; }); }else{ [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } }]; } - (void)gotoCustomCamera{ [UCAuthorityManager cameraAuthority:^{ YMCustomCameraViewModel *customCameraVM = [[YMCustomCameraViewModel alloc]initWithParams:@{}]; [YMRouter openURL:stringFormat(@"%@%@",YM_ROUTER_URL_PREFIX,YM_ROUTER_CUSTOM_CAMERA) withUserInfo:@{ RouterViewModel:customCameraVM } completion:nil]; // UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera; // if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) { // UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; // imagePicker.delegate = self; // imagePicker.sourceType = sourceType; // imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront; // imagePicker.modalPresentationStyle = UIModalPresentationOverCurrentContext; // imagePicker.allowsEditing = YES; // imagePicker.showsCameraControls = YES; // UIImageView *samplePhoto = [[UIImageView alloc]initWithFrame:CGRectMake(0, kFrameHeight - kYMNavHeight*2, adapt(100), adapt(100))]; // [samplePhoto sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.samplePhotoUrl] placeholderImage:[UIImage new] options:SDWebImageRefreshCached]; // imagePicker.cameraOverlayView = samplePhoto; // [[YMGlobalUtils getCurrentVC] presentViewController:imagePicker animated:YES completion:nil]; // } else { // NSLog(@"模拟器中无法打开照相机,请在真机中使用"); // } } denied:^{ YMTipsPopupView *customView = [[YMTipsPopupView alloc]init]; [customView configutationWithTips:@"请在iphone的“设置-隐私-相机”选项中,允许APP访问您的相机。" TipsAlignment:NSTextAlignmentCenter IsHideTitle:NO IsHideSingleButton:NO]; YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:[YMGlobalUtils getCurrentVC].view popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade]; popupView.priority = 999; popupView.cornerRadius = adapt(10); popupView.rectCorners = UIRectCornerAllCorners; popupView.positionStyle = YMPositionStyleCenter; popupView.isHideBg = NO; popupView.bgAlpha = 0.3; @weakify(popupView) customView.buttonBlock = ^(BOOL isConfirm) { @strongify(popupView) if (isConfirm) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil]; } [popupView dismissWithStyle:YMDismissStyleFade duration:2.0]; }; [popupView pop]; }]; } //- (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]; // } //} - (NSMutableArray *)auditPhotoArray{ if (!_auditPhotoArray) { _auditPhotoArray = [NSMutableArray array]; } return _auditPhotoArray; } - (RACSubject *)addAuditPhotoSubject{ if (!_addAuditPhotoSubject) { _addAuditPhotoSubject = [RACSubject subject]; } return _addAuditPhotoSubject; } - (RACSubject *)deleteAuditPhotoSubject{ if (!_deleteAuditPhotoSubject) { _deleteAuditPhotoSubject = [RACSubject subject]; } return _deleteAuditPhotoSubject; } @end