YMAuthenticationCenterViewModel.m 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //
  2. // YMAuthenticationCenterViewModel.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/3/2.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMAuthenticationCenterViewModel.h"
  9. @interface YMAuthenticationCenterViewModel ()<UINavigationControllerDelegate,UIImagePickerControllerDelegate>
  10. /// 示例照链接
  11. @property (nonatomic, strong, readwrite) NSString *samplePhotoUrl;
  12. /// 示例照类型
  13. @property (nonatomic, assign, readwrite) NSInteger samplePhotoType;
  14. /// 我的照片
  15. @property (nonatomic, strong, readwrite) UIImage *photo;
  16. /// 选中认证照数组
  17. @property (nonatomic, strong, readwrite) NSMutableArray <UIImage *>*auditPhotoArray;
  18. /// 添加认证照
  19. @property (nonatomic, strong, readwrite) RACSubject *addAuditPhotoSubject;
  20. /// 删除认证照
  21. @property (nonatomic, strong, readwrite) RACSubject *deleteAuditPhotoSubject;
  22. @end
  23. @implementation YMAuthenticationCenterViewModel
  24. - (void)ym_initialize{
  25. [super ym_initialize];
  26. self.customNavTitle = @"认证中心";
  27. self.samplePhotoUrl = [self.params stringValueForKey:ParamsUrl defaultValue:@""];
  28. self.samplePhotoType = [self.params integerValueForKey:ParamsSubType defaultValue:1];
  29. if([[self.params allKeys] containsObject:@"photo"]){
  30. self.photo = self.params[@"photo"];
  31. [self.auditPhotoArray addObject:self.photo];
  32. } else {
  33. self.photo = nil;
  34. }
  35. @weakify(self)
  36. [[self.addAuditPhotoSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id _Nullable photo) {
  37. @strongify(self)
  38. [self.auditPhotoArray removeAllObjects];
  39. [self.auditPhotoArray addObject:photo];
  40. }];
  41. [[self.deleteAuditPhotoSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id _Nullable photo) {
  42. @strongify(self)
  43. [self.auditPhotoArray removeAllObjects];
  44. }];
  45. }
  46. - (void)uploadAuthenticationPhotoData{
  47. if (self.auditPhotoArray.count <= 0) {
  48. YMTipsPopupView *customView = [[YMTipsPopupView alloc]init];
  49. [customView configutationWithTips:@"请根据“示例动作”进行拍照" TipsAlignment:NSTextAlignmentCenter IsHideTitle:NO IsHideSingleButton:NO];
  50. YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade];
  51. popupView.priority = 999;
  52. popupView.cornerRadius = adapt(10);
  53. popupView.rectCorners = UIRectCornerAllCorners;
  54. popupView.positionStyle = YMPositionStyleCenter;
  55. popupView.isHideBg = NO;
  56. popupView.bgAlpha = 0.3;
  57. @weakify(popupView)
  58. customView.buttonBlock = ^(BOOL isConfirm) {
  59. @strongify(popupView)
  60. [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
  61. };
  62. [popupView pop];
  63. return;
  64. }
  65. [ZCHUDHelper showWithStatus:@"上传中..."];
  66. [LCCommonHttp uploadImages:self.auditPhotoArray type:@"audit" succress:^(NSArray *imageArray){
  67. NSDictionary *dict = imageArray.lastObject;
  68. if ([[dict objectForKey:@"type"] isEqualToString:@"audit"]) {
  69. NSString *str = [dict objectForKey:@"url"];
  70. [LCHttpHelper requestWithURLString:UploadCameraAudit parameters:@{
  71. @"photo":str,
  72. @"action_type":@(self.samplePhotoType),
  73. } needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  74. NSDictionary* dict = (NSDictionary*)responseObject;
  75. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  76. if (code == 0) {
  77. [ZCHUDHelper showTitle:@"照片已提交"];
  78. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  79. [[YMGlobalUtils getCurrentVC].navigationController popViewControllerAnimated:YES];
  80. });
  81. }else{
  82. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  83. }
  84. } failure:^(NSError *error) {
  85. [ZCHUDHelper showTitle:error.localizedDescription];
  86. }];
  87. }
  88. }];
  89. }
  90. - (void)gotoCustomCamera{
  91. [UCAuthorityManager cameraAuthority:^{
  92. YMCustomCameraViewModel *customCameraVM = [[YMCustomCameraViewModel alloc]initWithParams:@{}];
  93. [YMRouter openURL:stringFormat(@"%@%@",YM_ROUTER_URL_PREFIX,YM_ROUTER_CUSTOM_CAMERA) withUserInfo:@{
  94. RouterViewModel:customCameraVM
  95. } completion:nil];
  96. // UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
  97. // if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
  98. // UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
  99. // imagePicker.delegate = self;
  100. // imagePicker.sourceType = sourceType;
  101. // imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
  102. // imagePicker.modalPresentationStyle = UIModalPresentationOverCurrentContext;
  103. // imagePicker.allowsEditing = YES;
  104. // imagePicker.showsCameraControls = YES;
  105. // UIImageView *samplePhoto = [[UIImageView alloc]initWithFrame:CGRectMake(0, kFrameHeight - kYMNavHeight*2, adapt(100), adapt(100))];
  106. // [samplePhoto sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.samplePhotoUrl] placeholderImage:[UIImage new] options:SDWebImageRefreshCached];
  107. // imagePicker.cameraOverlayView = samplePhoto;
  108. // [[YMGlobalUtils getCurrentVC] presentViewController:imagePicker animated:YES completion:nil];
  109. // } else {
  110. // NSLog(@"模拟器中无法打开照相机,请在真机中使用");
  111. // }
  112. } denied:^{
  113. YMTipsPopupView *customView = [[YMTipsPopupView alloc]init];
  114. [customView configutationWithTips:@"请在iphone的“设置-隐私-相机”选项中,允许APP访问您的相机。" TipsAlignment:NSTextAlignmentCenter IsHideTitle:NO IsHideSingleButton:NO];
  115. YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:[YMGlobalUtils getCurrentVC].view popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade];
  116. popupView.priority = 999;
  117. popupView.cornerRadius = adapt(10);
  118. popupView.rectCorners = UIRectCornerAllCorners;
  119. popupView.positionStyle = YMPositionStyleCenter;
  120. popupView.isHideBg = NO;
  121. popupView.bgAlpha = 0.3;
  122. @weakify(popupView)
  123. customView.buttonBlock = ^(BOOL isConfirm) {
  124. @strongify(popupView)
  125. if (isConfirm) {
  126. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
  127. }
  128. [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
  129. };
  130. [popupView pop];
  131. }];
  132. }
  133. //- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
  134. // [picker dismissViewControllerAnimated:YES completion:nil];
  135. // NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
  136. // if ([type isEqualToString:@"public.image"]) {
  137. // UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
  138. // }
  139. //}
  140. - (NSMutableArray<UIImage *> *)auditPhotoArray{
  141. if (!_auditPhotoArray) {
  142. _auditPhotoArray = [NSMutableArray array];
  143. }
  144. return _auditPhotoArray;
  145. }
  146. - (RACSubject *)addAuditPhotoSubject{
  147. if (!_addAuditPhotoSubject) {
  148. _addAuditPhotoSubject = [RACSubject subject];
  149. }
  150. return _addAuditPhotoSubject;
  151. }
  152. - (RACSubject *)deleteAuditPhotoSubject{
  153. if (!_deleteAuditPhotoSubject) {
  154. _deleteAuditPhotoSubject = [RACSubject subject];
  155. }
  156. return _deleteAuditPhotoSubject;
  157. }
  158. @end