YMAboutUsViewModel.m 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. //
  2. // YMAboutUsViewModel.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/21.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMAboutUsViewModel.h"
  9. #import "YMUpdateVersionModel.h"
  10. #import "YOUPAILCUpdateVersionVC.h"
  11. @interface YMAboutUsViewModel ()
  12. /// 列表数据
  13. @property (nonatomic, strong, readwrite) NSArray <YMAboutUsCellViewModel*>*listDataArray;
  14. /// 关于我们功能操作
  15. @property (nonatomic, strong, readwrite) RACSubject *aboutUsFunctionsOperationSubject;
  16. @end
  17. @implementation YMAboutUsViewModel
  18. - (void)ym_initialize{
  19. [super ym_initialize];
  20. NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];
  21. self.customNavTitle = stringFormat(@"关于%@",appName);
  22. @weakify(self)
  23. [[self.aboutUsFunctionsOperationSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id _Nullable value) {
  24. @strongify(self)
  25. switch ([value intValue]) {
  26. case YMAboutUsFunctionsTypeUserAgreement:
  27. {
  28. YMWebArticleViewModel *webArticleVM = [[YMWebArticleViewModel alloc]initWithParams:@{
  29. ParamsUrl:[NSString stringWithFormat:@"%@%@",[LCSaveData getBaseURL]?[LCSaveData getBaseURL]:BaseURL,UserProtocolH5]
  30. }];
  31. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_WEB_ARTICLE) withUserInfo:@{
  32. RouterViewModel:webArticleVM
  33. } completion:nil];
  34. }
  35. break;
  36. case YMAboutUsFunctionsTypePrivacyAgreement:
  37. {
  38. YMWebArticleViewModel *webArticleVM = [[YMWebArticleViewModel alloc]initWithParams:@{
  39. ParamsUrl:[NSString stringWithFormat:@"%@%@",[LCSaveData getBaseURL]?[LCSaveData getBaseURL]:BaseURL,UserPrivacyH5]
  40. }];
  41. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_WEB_ARTICLE) withUserInfo:@{
  42. RouterViewModel:webArticleVM
  43. } completion:nil];
  44. }
  45. break;
  46. // case YMAboutUsFunctionsTypeThirdPartyPersonalInfoList:
  47. // {
  48. //
  49. // }
  50. // break;
  51. // case YMAboutUsFunctionsTypePermissionRequestInstruction:
  52. // {
  53. //
  54. // }
  55. // break;
  56. case YMAboutUsFunctionsTypeDetectingVersionUpdates:
  57. {
  58. [self detectingVersionUpdates];
  59. }
  60. break;
  61. default:
  62. break;
  63. }
  64. }];
  65. }
  66. - (void)getAboutUsListData{
  67. self.listDataArray = [@[
  68. @{
  69. @"title":@"用户协议",
  70. ParamsCategoryType:@(YMAboutUsFunctionsTypeUserAgreement),
  71. },
  72. @{
  73. @"title":@"隐私保护",
  74. ParamsCategoryType:@(YMAboutUsFunctionsTypePrivacyAgreement),
  75. },
  76. // @{
  77. // @"title":@"第三方共享个人信息清单",
  78. // ParamsCategoryType:@(YMAboutUsFunctionsTypeThirdPartyPersonalInfoList),
  79. // },
  80. // @{
  81. // @"title":@"权限申请与使用情况说明",
  82. // ParamsCategoryType:@(YMAboutUsFunctionsTypePermissionRequestInstruction),
  83. // },
  84. @{
  85. @"title":@"检测版本更新",
  86. ParamsCategoryType:@(YMAboutUsFunctionsTypeDetectingVersionUpdates),
  87. },
  88. ].rac_sequence map:^(NSDictionary * _Nullable dic) {
  89. YMAboutUsCellViewModel *viewModel = [[YMAboutUsCellViewModel alloc]initWithParams:@{
  90. ParamsModel:dic
  91. }];
  92. return viewModel;
  93. }].array;
  94. [self.refreshUISubject sendNext:@(YMRefreshUI)];
  95. }
  96. - (void)detectingVersionUpdates{
  97. @weakify(self)
  98. [ZCHUDHelper showWithStatus:@"检测中..."];
  99. [LCHttpHelper requestWithURLString:CheckUpdateVersion parameters:@{
  100. @"update":@"update",
  101. @"channel":@(22)
  102. } needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  103. @strongify(self)
  104. NSDictionary* dict = (NSDictionary*)responseObject;
  105. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  106. if (code == 0) {
  107. NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}];
  108. YMUpdateVersionModel *model = [YMUpdateVersionModel yy_modelWithJSON:data];
  109. NSString *localVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
  110. if ([model.newversion compare:localVersion options:NSCaseInsensitiveSearch] > 0) {
  111. YMVersionUpdatePopupView *customView = [[YMVersionUpdatePopupView alloc]init];
  112. [customView configutationWithTips:stringFormat(@"v版本号:%@\n%@",model.newversion?:@"",model.upgradetext)];
  113. YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade];
  114. popupView.priority = 999;
  115. popupView.cornerRadius = adapt(10);
  116. popupView.rectCorners = UIRectCornerAllCorners;
  117. popupView.positionStyle = YMPositionStyleCenter;
  118. popupView.isHideBg = NO;
  119. popupView.bgAlpha = 0.3;
  120. [popupView pop];
  121. @weakify(popupView)
  122. customView.buttonBlock = ^(BOOL isConfirm) {
  123. @strongify(popupView)
  124. if (isConfirm) {
  125. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:model.downloadurl] options:@{} completionHandler:nil];
  126. }
  127. [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
  128. };
  129. }else{
  130. [ZCHUDHelper showTitle:@"已经是最新版本" showtime:1.5];
  131. }
  132. }else{
  133. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  134. }
  135. } failure:^(NSError *error) {
  136. [ZCHUDHelper showTitle:error.localizedDescription];
  137. }];
  138. }
  139. - (RACSubject *)aboutUsFunctionsOperationSubject{
  140. if (!_aboutUsFunctionsOperationSubject) {
  141. _aboutUsFunctionsOperationSubject = [RACSubject subject];
  142. }
  143. return _aboutUsFunctionsOperationSubject;
  144. }
  145. @end