AboutViewController.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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 "UseAccountManage.h"
  13. #import "CloudPhoneAPI.h"
  14. #import <MJExtension.h>
  15. @interface AboutViewController ()
  16. @property (nonatomic, strong) UIButton *ruleBtn;
  17. @property (nonatomic, strong) UIButton *privateBtn;
  18. @property (nonatomic, strong) HWVersionModel *versionModel;
  19. @end
  20. @implementation AboutViewController
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. [self drawAnyView];
  24. }
  25. - (void)viewDidAppear:(BOOL)animated {
  26. [super viewDidAppear:animated];
  27. }
  28. - (void)drawAnyView
  29. {
  30. [self.view setBackgroundColor:HWF5F7FAColor];
  31. self.navBarBGView.hidden = NO;
  32. [self.navigationBar setHidden:YES];
  33. [self.toolBar setHidden:YES];
  34. [self.titleLabel setText:@"检测更新"];
  35. // // 背景图片
  36. // CGFloat margin = 35; // 起始高度
  37. // UIImageView *bgImageView = [[UIImageView alloc] init];
  38. // [bgImageView setImage:[UIImage imageNamed:@"mine_136"]];
  39. // bgImageView.contentMode = UIViewContentModeScaleAspectFill;
  40. // [self.view addSubview:bgImageView];
  41. // [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  42. // make.top.mas_equalTo(margin);
  43. // make.left.mas_equalTo(0);
  44. // make.width.mas_equalTo(SCREEN_W);
  45. // make.height.mas_equalTo(SCREEN_W);
  46. // }];
  47. UIImageView *topImage = [[UIImageView alloc] init];
  48. [topImage setImage:[self getAppIcon]];
  49. [self.view addSubview:topImage];
  50. [topImage mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.width.mas_equalTo(90.f);
  52. make.height.mas_equalTo(90.f);
  53. make.centerX.equalTo(self.view.mas_centerX);
  54. make.top.equalTo(self.navBarBGView.mas_bottom).offset(123.f);
  55. }];
  56. /*app名*/
  57. UILabel *appName = [[UILabel alloc] init];
  58. [appName setBackgroundColor:[UIColor clearColor]];
  59. [appName setTextColor:HWFFFFFFColor];
  60. [appName setFont:[UIFont boldSystemFontOfSize:18.f]];
  61. [appName setTextAlignment:(NSTextAlignmentCenter)];
  62. [appName setText:[iPhone appBundleName]];
  63. [self.view addSubview:appName];
  64. [appName mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.top.equalTo(topImage.mas_bottom).offset(11.f);
  66. make.right.mas_equalTo(-27.f);
  67. make.left.mas_equalTo(27.f);
  68. make.height.mas_equalTo(22.f);
  69. }];
  70. /*app名*/
  71. UILabel *versionLabel = [[UILabel alloc] init];
  72. [versionLabel setBackgroundColor:[UIColor clearColor]];
  73. [versionLabel setTextColor:HWFFFFFFColor60];
  74. [versionLabel setFont:[UIFont systemFontOfSize:14.f]];
  75. [versionLabel setTextAlignment:(NSTextAlignmentCenter)];
  76. NSString *vers = [iPhone appVersion];
  77. [versionLabel setText:[NSString stringWithFormat:@"版本号%@",vers]];
  78. [self.view addSubview:versionLabel];
  79. [versionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.top.equalTo(appName.mas_bottom).offset(10.f);
  81. make.right.mas_equalTo(-27.f);
  82. make.left.mas_equalTo(27.f);
  83. make.height.mas_equalTo(20.f);
  84. }];
  85. UIButton *privateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  86. self.privateBtn = privateBtn;
  87. privateBtn.titleLabel.font = [UIFont boldSystemFontOfSize:16.f];
  88. [privateBtn setTitle:@"隐私协议" forState:UIControlStateNormal];
  89. [privateBtn setTitleColor:HWCFD1D4Color forState:UIControlStateNormal];
  90. [privateBtn setBackgroundColor:[UIColor clearColor]];
  91. [privateBtn addTarget:self action:@selector(privateBtnClick) forControlEvents:UIControlEventTouchUpInside];
  92. privateBtn.layer.cornerRadius = 8;
  93. privateBtn.layer.masksToBounds = YES;
  94. privateBtn.layer.borderColor = HWCFD1D4Color.CGColor;
  95. privateBtn.layer.borderWidth = 1;
  96. [self.view addSubview:privateBtn];
  97. [privateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  98. make.bottom.mas_equalTo(-120-AdaptTabHeight);
  99. make.width.mas_equalTo(SCREEN_W-38*2);
  100. make.height.mas_equalTo(48);
  101. make.left.mas_equalTo(38);
  102. }];
  103. UIButton *ruleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  104. self.ruleBtn = ruleBtn;
  105. ruleBtn.titleLabel.font = [UIFont boldSystemFontOfSize:16.f];
  106. [ruleBtn setTitle:@"用户使用协议" forState:UIControlStateNormal];
  107. [ruleBtn setTitleColor:HWCFD1D4Color forState:UIControlStateNormal];
  108. [ruleBtn setBackgroundColor:[UIColor clearColor]];
  109. [ruleBtn addTarget:self action:@selector(ruleBtnClick) forControlEvents:UIControlEventTouchUpInside];
  110. ruleBtn.layer.cornerRadius = 8;
  111. ruleBtn.layer.masksToBounds = YES;
  112. ruleBtn.layer.borderWidth = 1;
  113. ruleBtn.layer.borderColor = HWCFD1D4Color.CGColor;
  114. [self.view addSubview:ruleBtn];
  115. [ruleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  116. make.bottom.mas_equalTo(privateBtn.mas_top).mas_offset(-15);
  117. make.width.mas_equalTo(SCREEN_W-38*2);
  118. make.height.mas_equalTo(48);
  119. make.left.mas_equalTo(38);
  120. }];
  121. UIButton *versionCheckBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  122. [versionCheckBtn setTitle:@"版本检测" forState:UIControlStateNormal];
  123. versionCheckBtn.titleLabel.font = [UIFont boldSystemFontOfSize:16.f];
  124. [versionCheckBtn setTitleColor:HWCFD1D4Color forState:UIControlStateNormal];
  125. [versionCheckBtn setBackgroundColor:[UIColor clearColor]];
  126. [versionCheckBtn addTarget:self action:@selector(versionCheckBtnClick) forControlEvents:UIControlEventTouchUpInside];
  127. versionCheckBtn.layer.cornerRadius = 8;
  128. versionCheckBtn.layer.masksToBounds = YES;
  129. versionCheckBtn.layer.borderWidth = 1;
  130. versionCheckBtn.layer.borderColor = HWCFD1D4Color.CGColor;
  131. [self.view addSubview:versionCheckBtn];
  132. [versionCheckBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  133. make.bottom.mas_equalTo(ruleBtn.mas_top).mas_offset(-15);
  134. make.left.mas_equalTo(38);
  135. make.width.mas_equalTo(SCREEN_W-38*2);
  136. make.height.mas_equalTo(48);
  137. }];
  138. }
  139. - (UIImage *)getAppIcon{
  140. NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
  141. //获取app中所有icon名字数组
  142. NSArray *iconsArr = infoDict[@"CFBundleIcons"][@"CFBundlePrimaryIcon"][@"CFBundleIconFiles"];
  143. //取最后一个icon的名字
  144. NSString *iconLastName = [iconsArr lastObject];
  145. //打印icon名字
  146. NSLog(@"iconsArr: %@", iconsArr);
  147. NSLog(@"iconLastName: %@", iconLastName);
  148. return [UIImage imageNamed:iconLastName];
  149. }
  150. #pragma mark- 网络请求
  151. - (void)getVersion {
  152. [self showNewIndicatorHaveStrWithCanBack:YES canTouch:NO showText:@"检测新版本中…"];
  153. NSMutableDictionary *paraDict = [NSMutableDictionary dictionary];
  154. [paraDict setValue:@"ios" forKey:@"os"];
  155. NSString *appID = [[NSBundle mainBundle] bundleIdentifier];
  156. [paraDict setValue:appID forKey:@"packageName"];
  157. [[UseAccountManage shareInstance] CommonGetWithCallBackCode:AppVersionCheckAPI Parameters:paraDict success:^(id _Nonnull responseObject) {
  158. HLog(@"%@", responseObject);
  159. [self removeNewIndicatorHaveStr];
  160. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  161. if (model.status && model.status.integerValue == 0) {
  162. HWVersionModel *model = [HWVersionModel mj_objectWithKeyValues:responseObject[@"data"]];
  163. self.versionModel = model;
  164. [self checkVersion];
  165. }
  166. else
  167. {
  168. [[iToast makeText:model.msg] show];
  169. }
  170. } failure:^(NSError * _Nonnull error) {
  171. HLog(@"%@", error);
  172. [[iToast makeText:@"网络异常,请稍后重试!"] show];
  173. [self removeNewIndicatorHaveStr];
  174. }];
  175. }
  176. - (void)versionCheckBtnClick {
  177. [self getVersion];
  178. }
  179. - (void)checkVersion {
  180. // NSString *currentVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleVersion"];
  181. NSString *currentVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"];
  182. NSString *newVersion = [self.versionModel.versionNumber stringByReplacingOccurrencesOfString:@"v" withString:@""]; //去掉v
  183. // HLog(@"%@---%@", newVersion, currentVersion);
  184. if ([currentVersion compare:newVersion options:NSNumericSearch] == NSOrderedSame) { // 本地版本号 == 服务器版本号
  185. [self showNoNewVersion];
  186. [HWDataManager setBoolWithKey:Const_haveVersion value:NO];
  187. }else if ([currentVersion compare:newVersion options:NSNumericSearch] == NSOrderedDescending) { // 本地版本号 > 服务器版本号 (异常情况)
  188. [self showNoNewVersion];
  189. [HWDataManager setBoolWithKey:Const_haveVersion value:NO];
  190. }else { // 本地版本号 < 服务器版本号 (有新版本)
  191. self.versionModel.versionNumber = newVersion;
  192. [self showNewVersion];
  193. [HWDataManager setBoolWithKey:Const_haveVersion value:YES];
  194. };
  195. }
  196. - (void)showNewVersion {
  197. HaveNewVersionView *haveNewVersionView = [HaveNewVersionView shardInstance];
  198. if (haveNewVersionView.isShow) {
  199. return;
  200. }
  201. haveNewVersionView.versionModel = self.versionModel;
  202. haveNewVersionView.isContinueCheckAlert = NO; // 是否继续走下一步弹窗检测流程
  203. [haveNewVersionView setBackgroundColor:RGBACOLOR(0, 0, 0, 0.5)];
  204. [[[UIApplication sharedApplication] keyWindow] addSubview:haveNewVersionView];
  205. haveNewVersionView.isShow = YES;
  206. [haveNewVersionView mas_makeConstraints:^(MASConstraintMaker *make) {
  207. make.top.mas_equalTo(0);
  208. make.left.mas_equalTo(0);
  209. make.right.mas_equalTo(0);
  210. make.bottom.mas_equalTo(0);
  211. }];
  212. haveNewVersionView.alpha = 0.0;
  213. [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
  214. haveNewVersionView.alpha = 1.0;
  215. KyoLog(@"in animate start");
  216. } completion:^(BOOL finished) {
  217. KyoLog(@"in animate completion");
  218. }];
  219. }
  220. - (void)showNoNewVersion {
  221. [[iToast makeText:@"已是最新版本"] show];
  222. }
  223. - (void)ruleBtnClick {
  224. // [self gotoProtocolWKWebVCByPush:YES];
  225. }
  226. - (void)privateBtnClick {
  227. // [self gotoPrivateProtocolWKWebVCByPush:YES];
  228. }
  229. @end