123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- //
- // YMAboutUsViewModel.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/2/21.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMAboutUsViewModel.h"
- #import "YMUpdateVersionModel.h"
- #import "YOUPAILCUpdateVersionVC.h"
- @interface YMAboutUsViewModel ()
- /// 列表数据
- @property (nonatomic, strong, readwrite) NSArray <YMAboutUsCellViewModel*>*listDataArray;
- /// 关于我们功能操作
- @property (nonatomic, strong, readwrite) RACSubject *aboutUsFunctionsOperationSubject;
- @end
- @implementation YMAboutUsViewModel
- - (void)ym_initialize{
- [super ym_initialize];
- NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];
- self.customNavTitle = stringFormat(@"关于%@",appName);
- @weakify(self)
- [[self.aboutUsFunctionsOperationSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id _Nullable value) {
- @strongify(self)
- switch ([value intValue]) {
- case YMAboutUsFunctionsTypeUserAgreement:
- {
- YMWebArticleViewModel *webArticleVM = [[YMWebArticleViewModel alloc]initWithParams:@{
- ParamsUrl:[NSString stringWithFormat:@"%@%@",[LCSaveData getBaseURL]?[LCSaveData getBaseURL]:BaseURL,UserProtocolH5]
- }];
- [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_WEB_ARTICLE) withUserInfo:@{
- RouterViewModel:webArticleVM
- } completion:nil];
- }
- break;
- case YMAboutUsFunctionsTypePrivacyAgreement:
- {
- YMWebArticleViewModel *webArticleVM = [[YMWebArticleViewModel alloc]initWithParams:@{
- ParamsUrl:[NSString stringWithFormat:@"%@%@",[LCSaveData getBaseURL]?[LCSaveData getBaseURL]:BaseURL,UserPrivacyH5]
- }];
- [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_WEB_ARTICLE) withUserInfo:@{
- RouterViewModel:webArticleVM
- } completion:nil];
- }
- break;
- // case YMAboutUsFunctionsTypeThirdPartyPersonalInfoList:
- // {
- //
- // }
- // break;
- // case YMAboutUsFunctionsTypePermissionRequestInstruction:
- // {
- //
- // }
- // break;
- case YMAboutUsFunctionsTypeDetectingVersionUpdates:
- {
- [self detectingVersionUpdates];
- }
- break;
- default:
- break;
- }
- }];
- }
- - (void)getAboutUsListData{
- self.listDataArray = [@[
- @{
- @"title":@"用户协议",
- ParamsCategoryType:@(YMAboutUsFunctionsTypeUserAgreement),
- },
- @{
- @"title":@"隐私保护",
- ParamsCategoryType:@(YMAboutUsFunctionsTypePrivacyAgreement),
- },
- // @{
- // @"title":@"第三方共享个人信息清单",
- // ParamsCategoryType:@(YMAboutUsFunctionsTypeThirdPartyPersonalInfoList),
- // },
- // @{
- // @"title":@"权限申请与使用情况说明",
- // ParamsCategoryType:@(YMAboutUsFunctionsTypePermissionRequestInstruction),
- // },
- @{
- @"title":@"检测版本更新",
- ParamsCategoryType:@(YMAboutUsFunctionsTypeDetectingVersionUpdates),
- },
- ].rac_sequence map:^(NSDictionary * _Nullable dic) {
- YMAboutUsCellViewModel *viewModel = [[YMAboutUsCellViewModel alloc]initWithParams:@{
- ParamsModel:dic
- }];
- return viewModel;
- }].array;
-
- [self.refreshUISubject sendNext:@(YMRefreshUI)];
-
- }
- - (void)detectingVersionUpdates{
- @weakify(self)
- [ZCHUDHelper showWithStatus:@"检测中..."];
- [LCHttpHelper requestWithURLString:CheckUpdateVersion parameters:@{
- @"update":@"update",
- @"channel":@(22)
- } needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
- @strongify(self)
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}];
-
- YMUpdateVersionModel *model = [YMUpdateVersionModel yy_modelWithJSON:data];
-
- NSString *localVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
-
- if ([model.newversion compare:localVersion options:NSCaseInsensitiveSearch] > 0) {
-
- YMVersionUpdatePopupView *customView = [[YMVersionUpdatePopupView alloc]init];
- [customView configutationWithTips:stringFormat(@"v版本号:%@\n%@",model.newversion?:@"",model.upgradetext)];
- 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;
- [popupView pop];
-
- @weakify(popupView)
- customView.buttonBlock = ^(BOOL isConfirm) {
- @strongify(popupView)
- if (isConfirm) {
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:model.downloadurl] options:@{} completionHandler:nil];
- }
- [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
- };
-
- }else{
- [ZCHUDHelper showTitle:@"已经是最新版本" showtime:1.5];
- }
-
- }else{
- [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
- }
- } failure:^(NSError *error) {
- [ZCHUDHelper showTitle:error.localizedDescription];
- }];
- }
- - (RACSubject *)aboutUsFunctionsOperationSubject{
- if (!_aboutUsFunctionsOperationSubject) {
- _aboutUsFunctionsOperationSubject = [RACSubject subject];
- }
- return _aboutUsFunctionsOperationSubject;
- }
- @end
|