123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- //
- // YMAuthenticationCenterViewModel.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/3/2.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMAuthenticationCenterViewModel.h"
- @interface YMAuthenticationCenterViewModel ()<UINavigationControllerDelegate,UIImagePickerControllerDelegate>
- /// 示例照链接
- @property (nonatomic, strong, readwrite) NSString *samplePhotoUrl;
- /// 示例照类型
- @property (nonatomic, assign, readwrite) NSInteger samplePhotoType;
- /// 我的照片
- @property (nonatomic, strong, readwrite) UIImage *photo;
- /// 选中认证照数组
- @property (nonatomic, strong, readwrite) NSMutableArray <UIImage *>*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<UIImage *> *)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
|