AboutViewController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. //暂时屏蔽 等版本上了蒲公英再放开
  107. _checUpdatekBtn.hidden = YES;
  108. UIButton *privateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  109. self.privateBtn = privateBtn;
  110. privateBtn.titleLabel.font = [UIFont systemFontOfSize:13.f];
  111. [privateBtn setTitle:NSLocalizedString(@"app_update_private",nil) forState:UIControlStateNormal];
  112. [privateBtn setTitleColor:HW13B2EBColor forState:UIControlStateNormal];
  113. [privateBtn setBackgroundColor:[UIColor clearColor]];
  114. [privateBtn addTarget:self action:@selector(privateBtnClick) forControlEvents:UIControlEventTouchUpInside];
  115. privateBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  116. [self.view addSubview:privateBtn];
  117. [privateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  118. make.bottom.mas_equalTo(-80-AdaptTabHeight);
  119. //make.width.mas_equalTo(55);
  120. make.width.mas_equalTo(120);
  121. make.height.mas_equalTo(38);
  122. make.left.equalTo(self.view.mas_centerX).offset(6);
  123. }];
  124. UIButton *ruleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  125. self.ruleBtn = ruleBtn;
  126. ruleBtn.titleLabel.font = [UIFont systemFontOfSize:13.f];
  127. [ruleBtn setTitle:NSLocalizedString(@"app_update_use_deal",nil) forState:UIControlStateNormal];
  128. [ruleBtn setTitleColor:HW13B2EBColor forState:UIControlStateNormal];
  129. [ruleBtn setBackgroundColor:[UIColor clearColor]];
  130. [ruleBtn addTarget:self action:@selector(ruleBtnClick) forControlEvents:UIControlEventTouchUpInside];
  131. ruleBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  132. [self.view addSubview:ruleBtn];
  133. [ruleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  134. make.bottom.mas_equalTo(-80-AdaptTabHeight);
  135. //make.width.mas_equalTo(55);
  136. make.width.mas_equalTo(120);
  137. make.height.mas_equalTo(38);
  138. make.right.equalTo(self.view.mas_centerX).offset(-6);
  139. }];
  140. UIView *lineView = [[UIView alloc] init];
  141. [lineView setBackgroundColor:HW999999Color];
  142. [self.view addSubview:lineView];
  143. [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  144. make.centerX.equalTo(self.view.mas_centerX);
  145. make.width.mas_equalTo(1);
  146. make.height.mas_equalTo(14);
  147. make.centerY.equalTo(ruleBtn.mas_centerY);
  148. }];
  149. self.privateBtn.hidden = YES;
  150. self.ruleBtn.hidden = YES;
  151. lineView.hidden = YES;
  152. }
  153. - (UIImage *)getAppIcon{
  154. NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
  155. //获取app中所有icon名字数组
  156. NSArray *iconsArr = infoDict[@"CFBundleIcons"][@"CFBundlePrimaryIcon"][@"CFBundleIconFiles"];
  157. //取最后一个icon的名字
  158. NSString *iconLastName = [iconsArr lastObject];
  159. //打印icon名字
  160. NSLog(@"iconsArr: %@", iconsArr);
  161. NSLog(@"iconLastName: %@", iconLastName);
  162. return [UIImage imageNamed:iconLastName];
  163. }
  164. #pragma mark- 网络请求
  165. - (void)getVersion {
  166. [self showNewIndicatorHaveStrWithCanBack:YES canTouch:NO showText:NSLocalizedString(@"app_update_checking",nil)];
  167. NSMutableDictionary *paraDict = [NSMutableDictionary dictionary];
  168. [paraDict setValue:@"ios" forKey:@"type"];
  169. [paraDict setValue:@"skyworth" forKey:@"source"];
  170. [[netWorkManager shareInstance] CommonGetWithCallBackCode:upgradeNewVersion Parameters:paraDict success:^(id _Nonnull responseObject) {
  171. HLog(@"%@", responseObject);
  172. [self removeNewIndicatorHaveStr];
  173. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  174. if (model.status == 0) {
  175. HWVersionModel *model = [HWVersionModel mj_objectWithKeyValues:responseObject[@"data"]];
  176. self.versionModel = model;
  177. [self checkVersion];
  178. }
  179. else
  180. {
  181. [[iToast makeText:model.msg] show];
  182. }
  183. } failure:^(NSError * _Nonnull error) {
  184. HLog(@"%@", error);
  185. [[iToast makeText:@"网络异常,请稍后重试!"] show];
  186. [self removeNewIndicatorHaveStr];
  187. }];
  188. }
  189. - (void)versionCheckBtnClick {
  190. [self getVersion];
  191. }
  192. - (void)checkVersion {
  193. // NSString *currentVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleVersion"];
  194. NSString *currentVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"];
  195. NSString *newVersion = [self.versionModel.versionNumber stringByReplacingOccurrencesOfString:@"v" withString:@""]; //去掉v
  196. // HLog(@"%@---%@", newVersion, currentVersion);
  197. if ([currentVersion compare:newVersion options:NSNumericSearch] == NSOrderedSame) { // 本地版本号 == 服务器版本号
  198. // [self showNoNewVersion];
  199. [self showNewVersion];
  200. [HWDataManager setBoolWithKey:Const_haveVersion value:NO];
  201. // _checUpdatekBtn.enabled = NO;
  202. // _checUpdatekBtn.backgroundColor = [UIColor hwColor:@"#959799" alpha:1.0];
  203. // [_gl_checkVersonBut removeFromSuperlayer];
  204. }else if ([currentVersion compare:newVersion options:NSNumericSearch] == NSOrderedDescending) { // 本地版本号 > 服务器版本号 (异常情况)
  205. [self showNoNewVersion];
  206. [HWDataManager setBoolWithKey:Const_haveVersion value:NO];
  207. // _checUpdatekBtn.enabled = NO;
  208. // _checUpdatekBtn.backgroundColor = [UIColor hwColor:@"#959799" alpha:1.0];
  209. // [_gl_checkVersonBut removeFromSuperlayer];
  210. }else { // 本地版本号 < 服务器版本号 (有新版本)
  211. self.versionModel.versionNumber = newVersion;
  212. [self showNewVersion];
  213. [HWDataManager setBoolWithKey:Const_haveVersion value:YES];
  214. };
  215. }
  216. - (void)showNewVersion {
  217. HaveNewVersionView *haveNewVersionView = [HaveNewVersionView shardInstance];
  218. if (haveNewVersionView.isShow) {
  219. return;
  220. }
  221. haveNewVersionView.versionModel = self.versionModel;
  222. haveNewVersionView.isContinueCheckAlert = NO; // 是否继续走下一步弹窗检测流程
  223. [haveNewVersionView setBackgroundColor:RGBACOLOR(0, 0, 0, 0.5)];
  224. [[[UIApplication sharedApplication] keyWindow] addSubview:haveNewVersionView];
  225. haveNewVersionView.isShow = YES;
  226. if(!self.versionModel.necessary){
  227. haveNewVersionView.deleteBtn.hidden = NO;
  228. }
  229. [haveNewVersionView mas_makeConstraints:^(MASConstraintMaker *make) {
  230. make.top.mas_equalTo(0);
  231. make.left.mas_equalTo(0);
  232. make.right.mas_equalTo(0);
  233. make.bottom.mas_equalTo(0);
  234. }];
  235. haveNewVersionView.alpha = 0.0;
  236. [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
  237. haveNewVersionView.alpha = 1.0;
  238. KyoLog(@"in animate start");
  239. } completion:^(BOOL finished) {
  240. KyoLog(@"in animate completion");
  241. }];
  242. }
  243. - (void)showNoNewVersion {
  244. [[iToast makeText:NSLocalizedString(@"app_update_last_version",nil)] show];
  245. }
  246. - (void)ruleBtnClick {
  247. //https://cliys.armclouding.com/h5/protocol/protocol.html?agreementCoding=YSZYHXY2002&type=1
  248. // [self gotoProtocolWKWebVCByPush:YES];
  249. CustomerWebViewController *vc = [[CustomerWebViewController alloc] init];
  250. vc.titleStr = NSLocalizedString(@"app_update_use_deal",nil);
  251. NSString *url = @"https://cliys.armclouding.com/h5/protocol/protocol.html?agreementCoding=YSZYHXY2004&type=1";//[NSString stringWithFormat:@"%@/h5/protocol/protocol.html?agreementCoding=YSZYHXY2002&type=1", CloudService];
  252. vc.webUrl = url;
  253. [self.navigationController pushViewController:vc animated:YES];
  254. }
  255. - (void)privateBtnClick {
  256. // [self gotoPrivateProtocolWKWebVCByPush:YES];
  257. CustomerWebViewController *vc = [[CustomerWebViewController alloc] init];
  258. vc.titleStr = NSLocalizedString(@"app_update_private",nil);
  259. NSString *url = @"https://cliys.armclouding.com/h5/protocol/protocol.html?agreementCoding=YSZYSXY2003&type=1";//[NSString stringWithFormat:@"%@/h5/protocol/protocol.html?agreementCoding=YSZYSXY2001&type=1", CloudService];
  260. vc.webUrl = url;
  261. [self.navigationController pushViewController:vc animated:YES];
  262. }
  263. @end