AboutViewController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. //
  2. // AboutViewController.m
  3. // VclustersGemini
  4. //
  5. // Created by APPLE on 2020/2/24.
  6. // Copyright © 2020 APPLE. All rights reserved.
  7. //
  8. #import "AboutViewController.h"
  9. #import "HaveNewVersionView.h"
  10. #import "HWVersionModel.h"
  11. #import "iPhone.h"
  12. #import "CloudPhoneAPI.h"
  13. #import <MJExtension.h>
  14. #import "CustomerWebViewController.h"
  15. #import "netWorkManager.h"
  16. #import "SuperModel.h"
  17. @interface AboutViewController ()
  18. @property (nonatomic, strong) UIButton *checUpdatekBtn;
  19. // gradient
  20. @property (nonatomic, strong)CAGradientLayer *gl_checkVersonBut;
  21. @property (nonatomic, strong) UIButton *ruleBtn;
  22. @property (nonatomic, strong) UIButton *privateBtn;
  23. @property (nonatomic, strong) HWVersionModel *versionModel;
  24. @end
  25. @implementation AboutViewController
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. [self drawAnyView];
  29. }
  30. - (void)viewDidAppear:(BOOL)animated {
  31. [super viewDidAppear:animated];
  32. }
  33. - (void)drawAnyView
  34. {
  35. [self.view setBackgroundColor:HWF5F7FAColor];
  36. self.navBarBGView.hidden = NO;
  37. [self.navigationBar setHidden:YES];
  38. [self.toolBar setHidden:YES];
  39. [self.titleLabel setText:NSLocalizedString(@"app_update_title",nil)];
  40. UIImageView *topImage = [[UIImageView alloc] init];
  41. [topImage setImage:[self getAppIcon]];
  42. [self.view addSubview:topImage];
  43. [topImage mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.width.mas_equalTo(72.f);
  45. make.height.mas_equalTo(72.f);
  46. make.centerX.equalTo(self.view.mas_centerX);
  47. make.top.equalTo(self.navBarBGView.mas_bottom).offset(123.f);
  48. }];
  49. [topImage.layer setCornerRadius:15.f];
  50. topImage.clipsToBounds = YES;
  51. /*app名*/
  52. UILabel *appName = [[UILabel alloc] init];
  53. [appName setBackgroundColor:[UIColor clearColor]];
  54. [appName setTextColor:HW333333Color];
  55. [appName setFont:[UIFont boldSystemFontOfSize:16.f]];
  56. [appName setTextAlignment:(NSTextAlignmentCenter)];
  57. [appName setText:[NSString stringWithFormat:@"%@",[iPhone appBundleName]]];
  58. //[appName setText:[NSString stringWithFormat:@"%@",@"Private- X"]];
  59. [self.view addSubview:appName];
  60. [appName mas_makeConstraints:^(MASConstraintMaker *make) {
  61. make.top.equalTo(topImage.mas_bottom).offset(20.f);
  62. make.right.mas_equalTo(-27.f);
  63. make.left.mas_equalTo(27.f);
  64. make.height.mas_equalTo(22.f);
  65. }];
  66. /*版本号*/
  67. UILabel *versionLabel = [[UILabel alloc] init];
  68. [versionLabel setBackgroundColor:[UIColor clearColor]];
  69. [versionLabel setTextColor:HW333333Color];
  70. [versionLabel setFont:[UIFont systemFontOfSize:13.f]];
  71. [versionLabel setTextAlignment:(NSTextAlignmentCenter)];
  72. NSString *vers = [iPhone appVersion];
  73. [versionLabel setText:[NSString stringWithFormat:@"V%@",vers]];
  74. [self.view addSubview:versionLabel];
  75. [versionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  76. make.top.equalTo(appName.mas_bottom).offset(10.f);
  77. make.right.mas_equalTo(-27.f);
  78. make.left.mas_equalTo(27.f);
  79. make.height.mas_equalTo(20.f);
  80. }];
  81. /*开始体验*/
  82. _checUpdatekBtn = [[UIButton alloc] init];
  83. _checUpdatekBtn.frame = CGRectMake(0, 0, 160.f, 48.f);
  84. // gradient
  85. _gl_checkVersonBut = [CAGradientLayer layer];
  86. _gl_checkVersonBut.frame = CGRectMake(0,0,160.f,48.f);
  87. _gl_checkVersonBut.startPoint = CGPointMake(0, 0.5);
  88. _gl_checkVersonBut.endPoint = CGPointMake(1, 0.5);
  89. _gl_checkVersonBut.colors = @[(__bridge id)HW0CDEFDColor.CGColor, (__bridge id)HW058DFBColor.CGColor];
  90. _gl_checkVersonBut.locations = @[@(0), @(1.0f)];
  91. [_checUpdatekBtn.layer addSublayer:_gl_checkVersonBut];
  92. [_checUpdatekBtn addTarget:self action:@selector(versionCheckBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
  93. [_checUpdatekBtn setTitle:NSLocalizedString(@"app_update_check",nil) forState:(UIControlStateNormal)];
  94. [_checUpdatekBtn setTitle:NSLocalizedString(@"app_update_last_version",nil) forState:(UIControlStateDisabled)];
  95. [_checUpdatekBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  96. [_checUpdatekBtn.titleLabel setFont:[UIFont systemFontOfSize:16.f]];
  97. [_checUpdatekBtn.layer setCornerRadius:8.f];
  98. _checUpdatekBtn.clipsToBounds = YES;
  99. [self.view addSubview:_checUpdatekBtn];
  100. [_checUpdatekBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  101. make.centerX.equalTo(self.view.mas_centerX);
  102. make.width.mas_equalTo(160.f);
  103. make.top.equalTo(versionLabel.mas_bottom).offset(25.f);
  104. make.height.mas_equalTo(48.f);
  105. }];
  106. UIButton *privateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  107. self.privateBtn = privateBtn;
  108. privateBtn.titleLabel.font = [UIFont systemFontOfSize:13.f];
  109. [privateBtn setTitle:NSLocalizedString(@"app_update_private",nil) forState:UIControlStateNormal];
  110. [privateBtn setTitleColor:HW13B2EBColor forState:UIControlStateNormal];
  111. [privateBtn setBackgroundColor:[UIColor clearColor]];
  112. [privateBtn addTarget:self action:@selector(privateBtnClick) forControlEvents:UIControlEventTouchUpInside];
  113. privateBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  114. [self.view addSubview:privateBtn];
  115. [privateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  116. make.bottom.mas_equalTo(-80-AdaptTabHeight);
  117. //make.width.mas_equalTo(55);
  118. make.width.mas_equalTo(120);
  119. make.height.mas_equalTo(38);
  120. make.left.equalTo(self.view.mas_centerX).offset(6);
  121. }];
  122. UIButton *ruleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  123. self.ruleBtn = ruleBtn;
  124. ruleBtn.titleLabel.font = [UIFont systemFontOfSize:13.f];
  125. [ruleBtn setTitle:NSLocalizedString(@"app_update_use_deal",nil) forState:UIControlStateNormal];
  126. [ruleBtn setTitleColor:HW13B2EBColor forState:UIControlStateNormal];
  127. [ruleBtn setBackgroundColor:[UIColor clearColor]];
  128. [ruleBtn addTarget:self action:@selector(ruleBtnClick) forControlEvents:UIControlEventTouchUpInside];
  129. ruleBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  130. [self.view addSubview:ruleBtn];
  131. [ruleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  132. make.bottom.mas_equalTo(-80-AdaptTabHeight);
  133. //make.width.mas_equalTo(55);
  134. make.width.mas_equalTo(120);
  135. make.height.mas_equalTo(38);
  136. make.right.equalTo(self.view.mas_centerX).offset(-6);
  137. }];
  138. UIView *lineView = [[UIView alloc] init];
  139. [lineView setBackgroundColor:HW999999Color];
  140. [self.view addSubview:lineView];
  141. [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  142. make.centerX.equalTo(self.view.mas_centerX);
  143. make.width.mas_equalTo(1);
  144. make.height.mas_equalTo(14);
  145. make.centerY.equalTo(ruleBtn.mas_centerY);
  146. }];
  147. }
  148. - (UIImage *)getAppIcon{
  149. NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
  150. //获取app中所有icon名字数组
  151. NSArray *iconsArr = infoDict[@"CFBundleIcons"][@"CFBundlePrimaryIcon"][@"CFBundleIconFiles"];
  152. //取最后一个icon的名字
  153. NSString *iconLastName = [iconsArr lastObject];
  154. //打印icon名字
  155. NSLog(@"iconsArr: %@", iconsArr);
  156. NSLog(@"iconLastName: %@", iconLastName);
  157. return [UIImage imageNamed:iconLastName];
  158. }
  159. #pragma mark- 网络请求
  160. - (void)getVersion {
  161. [self showNewIndicatorHaveStrWithCanBack:YES canTouch:NO showText:NSLocalizedString(@"app_update_checking",nil)];
  162. NSMutableDictionary *paraDict = [NSMutableDictionary dictionary];
  163. [paraDict setValue:@"ios" forKey:@"type"];
  164. [paraDict setValue:@"skyworth" forKey:@"source"];
  165. [[netWorkManager shareInstance] CommonGetWithCallBackCode:upgradeNewVersion Parameters:paraDict success:^(id _Nonnull responseObject) {
  166. HLog(@"%@", responseObject);
  167. [self removeNewIndicatorHaveStr];
  168. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  169. if (model.status == 0) {
  170. HWVersionModel *model = [HWVersionModel mj_objectWithKeyValues:responseObject[@"data"]];
  171. self.versionModel = model;
  172. [self checkVersion];
  173. }
  174. else
  175. {
  176. [[iToast makeText:model.msg] show];
  177. }
  178. } failure:^(NSError * _Nonnull error) {
  179. HLog(@"%@", error);
  180. [[iToast makeText:@"网络异常,请稍后重试!"] show];
  181. [self removeNewIndicatorHaveStr];
  182. }];
  183. }
  184. - (void)versionCheckBtnClick {
  185. [self getVersion];
  186. }
  187. - (void)checkVersion {
  188. // NSString *currentVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleVersion"];
  189. NSString *currentVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"];
  190. NSString *newVersion = [self.versionModel.versionNumber stringByReplacingOccurrencesOfString:@"v" withString:@""]; //去掉v
  191. // HLog(@"%@---%@", newVersion, currentVersion);
  192. if ([currentVersion compare:newVersion options:NSNumericSearch] == NSOrderedSame) { // 本地版本号 == 服务器版本号
  193. // [self showNoNewVersion];
  194. [self showNewVersion];
  195. [HWDataManager setBoolWithKey:Const_haveVersion value:NO];
  196. // _checUpdatekBtn.enabled = NO;
  197. // _checUpdatekBtn.backgroundColor = [UIColor hwColor:@"#959799" alpha:1.0];
  198. // [_gl_checkVersonBut removeFromSuperlayer];
  199. }else if ([currentVersion compare:newVersion options:NSNumericSearch] == NSOrderedDescending) { // 本地版本号 > 服务器版本号 (异常情况)
  200. [self showNoNewVersion];
  201. [HWDataManager setBoolWithKey:Const_haveVersion value:NO];
  202. // _checUpdatekBtn.enabled = NO;
  203. // _checUpdatekBtn.backgroundColor = [UIColor hwColor:@"#959799" alpha:1.0];
  204. // [_gl_checkVersonBut removeFromSuperlayer];
  205. }else { // 本地版本号 < 服务器版本号 (有新版本)
  206. self.versionModel.versionNumber = newVersion;
  207. [self showNewVersion];
  208. [HWDataManager setBoolWithKey:Const_haveVersion value:YES];
  209. };
  210. }
  211. - (void)showNewVersion {
  212. HaveNewVersionView *haveNewVersionView = [HaveNewVersionView shardInstance];
  213. if (haveNewVersionView.isShow) {
  214. return;
  215. }
  216. haveNewVersionView.versionModel = self.versionModel;
  217. haveNewVersionView.isContinueCheckAlert = NO; // 是否继续走下一步弹窗检测流程
  218. [haveNewVersionView setBackgroundColor:RGBACOLOR(0, 0, 0, 0.5)];
  219. [[[UIApplication sharedApplication] keyWindow] addSubview:haveNewVersionView];
  220. haveNewVersionView.isShow = YES;
  221. if(!self.versionModel.necessary){
  222. haveNewVersionView.deleteBtn.hidden = NO;
  223. }
  224. [haveNewVersionView mas_makeConstraints:^(MASConstraintMaker *make) {
  225. make.top.mas_equalTo(0);
  226. make.left.mas_equalTo(0);
  227. make.right.mas_equalTo(0);
  228. make.bottom.mas_equalTo(0);
  229. }];
  230. haveNewVersionView.alpha = 0.0;
  231. [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
  232. haveNewVersionView.alpha = 1.0;
  233. KyoLog(@"in animate start");
  234. } completion:^(BOOL finished) {
  235. KyoLog(@"in animate completion");
  236. }];
  237. }
  238. - (void)showNoNewVersion {
  239. [[iToast makeText:NSLocalizedString(@"app_update_last_version",nil)] show];
  240. }
  241. - (void)ruleBtnClick {
  242. //https://cliys.armclouding.com/h5/protocol/protocol.html?agreementCoding=YSZYHXY2002&type=1
  243. // [self gotoProtocolWKWebVCByPush:YES];
  244. CustomerWebViewController *vc = [[CustomerWebViewController alloc] init];
  245. vc.titleStr = NSLocalizedString(@"app_update_use_deal",nil);
  246. NSString *url = @"https://cliys.armclouding.com/h5/protocol/protocol.html?agreementCoding=YSZYHXY2003&type=1";//[NSString stringWithFormat:@"%@/h5/protocol/protocol.html?agreementCoding=YSZYHXY2002&type=1", CloudService];
  247. vc.webUrl = url;
  248. [self.navigationController pushViewController:vc animated:YES];
  249. }
  250. - (void)privateBtnClick {
  251. // [self gotoPrivateProtocolWKWebVCByPush:YES];
  252. CustomerWebViewController *vc = [[CustomerWebViewController alloc] init];
  253. vc.titleStr = NSLocalizedString(@"app_update_private",nil);
  254. NSString *url = @"https://cliys.armclouding.com/h5/protocol/protocol.html?agreementCoding=YSZYSXY2002&type=1";//[NSString stringWithFormat:@"%@/h5/protocol/protocol.html?agreementCoding=YSZYSXY2001&type=1", CloudService];
  255. vc.webUrl = url;
  256. [self.navigationController pushViewController:vc animated:YES];
  257. }
  258. @end