AboutViewController.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. //
  2. // AboutViewController.m
  3. // //
  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. #import "allVersionView.h"
  18. #import "baseTableViewCell.h"
  19. #import "couldphoneSysInfoModel.h"
  20. @interface AboutViewController ()<UITableViewDelegate,UITableViewDataSource>
  21. @property (nonatomic, strong) UIButton *checUpdatekBtn;
  22. // gradient
  23. @property (nonatomic, strong)CAGradientLayer *gl_checkVersonBut;
  24. @property (nonatomic, strong) UIButton *ruleBtn;
  25. @property (nonatomic, strong) UIButton *privateBtn;
  26. @property (nonatomic, strong) HWVersionModel *versionModel;
  27. @property (nonatomic, strong) UITableView* tableView;
  28. @property (nonatomic, strong) NSArray* msgTitleArr;
  29. @property(nonatomic,strong)couldphoneSysInfoModel *couldphoneSysInfoMod;
  30. @end
  31. @implementation AboutViewController
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getCouldPhoneBaseInfoFun:) name:getCouldPhoneSysInfoNotification object:nil];
  35. [self drawAnyView];
  36. //数据埋点
  37. [[netWorkManager shareInstance] DataEmbeddingPointBy:2 withEventValue:@"Version_information"];
  38. if(_getSysInfo){
  39. _getSysInfo();
  40. }
  41. }
  42. - (void)viewDidAppear:(BOOL)animated {
  43. [super viewDidAppear:animated];
  44. }
  45. - (void)drawAnyView
  46. {
  47. [self.view setBackgroundColor:HWF5F7FAColor];
  48. self.navBarBGView.hidden = NO;
  49. [self.navigationBar setHidden:YES];
  50. [self.toolBar setHidden:YES];
  51. [self.titleLabel setText:NSLocalizedString(@"app_update_title",nil)];
  52. UIImageView *topImage = [[UIImageView alloc] init];
  53. [topImage setImage:[self getAppIcon]];
  54. topImage.userInteractionEnabled = YES;
  55. [self.view addSubview:topImage];
  56. [topImage mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.width.mas_equalTo(72.f);
  58. make.height.mas_equalTo(72.f);
  59. make.centerX.equalTo(self.view.mas_centerX);
  60. make.top.equalTo(self.navBarBGView.mas_bottom).offset(60.f);
  61. }];
  62. [topImage.layer setCornerRadius:15.f];
  63. topImage.clipsToBounds = YES;
  64. UITapGestureRecognizer *tap5 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTap5NumFun)];
  65. tap5.numberOfTapsRequired = 5;
  66. [topImage addGestureRecognizer:tap5];
  67. /*app名*/
  68. UILabel *appName = [[UILabel alloc] init];
  69. [appName setBackgroundColor:[UIColor clearColor]];
  70. [appName setTextColor:HW333333Color];
  71. [appName setFont:[UIFont boldSystemFontOfSize:16.f]];
  72. [appName setTextAlignment:(NSTextAlignmentCenter)];
  73. [appName setText:[NSString stringWithFormat:@"%@",[iPhone appBundleName]]];
  74. //[appName setText:[NSString stringWithFormat:@"%@",@"GBOX"]];
  75. [self.view addSubview:appName];
  76. [appName mas_makeConstraints:^(MASConstraintMaker *make) {
  77. make.top.equalTo(topImage.mas_bottom).offset(20.f);
  78. make.right.mas_equalTo(-27.f);
  79. make.left.mas_equalTo(27.f);
  80. make.height.mas_equalTo(22.f);
  81. }];
  82. /*版本号*/
  83. // UILabel *versionLabel = [[UILabel alloc] init];
  84. // [versionLabel setBackgroundColor:[UIColor clearColor]];
  85. // [versionLabel setTextColor:HW333333Color];
  86. // [versionLabel setFont:[UIFont systemFontOfSize:13.f]];
  87. // [versionLabel setTextAlignment:(NSTextAlignmentCenter)];
  88. // NSString *vers = [iPhone appVersion];
  89. // [versionLabel setText:[NSString stringWithFormat:@"V%@",vers]];
  90. // [self.view addSubview:versionLabel];
  91. // [versionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  92. // make.top.equalTo(appName.mas_bottom).offset(10.f);
  93. // make.right.mas_equalTo(-27.f);
  94. // make.left.mas_equalTo(27.f);
  95. // make.height.mas_equalTo(20.f);
  96. // }];
  97. /*开始体验*/
  98. _checUpdatekBtn = [[UIButton alloc] init];
  99. _checUpdatekBtn.frame = CGRectMake(0, 0, 160.f, 48.f);
  100. // gradient
  101. _gl_checkVersonBut = [CAGradientLayer layer];
  102. _gl_checkVersonBut.frame = CGRectMake(0,0,160.f,48.f);
  103. _gl_checkVersonBut.startPoint = CGPointMake(0, 0.5);
  104. _gl_checkVersonBut.endPoint = CGPointMake(1, 0.5);
  105. _gl_checkVersonBut.colors = @[(__bridge id)HWFFE10FColor.CGColor, (__bridge id)HWFFE411Color.CGColor];
  106. _gl_checkVersonBut.locations = @[@(0), @(1.0f)];
  107. [_checUpdatekBtn.layer addSublayer:_gl_checkVersonBut];
  108. [_checUpdatekBtn addTarget:self action:@selector(versionCheckBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
  109. [_checUpdatekBtn setTitle:NSLocalizedString(@"app_update_check",nil) forState:(UIControlStateNormal)];
  110. [_checUpdatekBtn setTitle:NSLocalizedString(@"app_update_last_version",nil) forState:(UIControlStateDisabled)];
  111. [_checUpdatekBtn setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
  112. [_checUpdatekBtn.titleLabel setFont:[UIFont systemFontOfSize:16.f]];
  113. [_checUpdatekBtn.layer setCornerRadius:8.f];
  114. _checUpdatekBtn.clipsToBounds = YES;
  115. [self.view addSubview:_checUpdatekBtn];
  116. [_checUpdatekBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  117. make.centerX.equalTo(self.view.mas_centerX);
  118. make.width.mas_equalTo(160.f);
  119. //make.top.equalTo(versionLabel.mas_bottom).offset(25.f);
  120. make.top.equalTo(appName.mas_bottom).offset(25.f);
  121. make.height.mas_equalTo(48.f);
  122. }];
  123. //新加一个tableview 显示镜像相关信息
  124. //app当前版本 系统当前版本 系统待更新版本
  125. _msgTitleArr = @[NSLocalizedString(@"app_version_current",nil)
  126. ,NSLocalizedString(@"system_version_current",nil)
  127. ,NSLocalizedString(@"asystem_version_wait_update",nil)];
  128. [self.view addSubview:self.tableView];
  129. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  130. make.left.mas_equalTo(15.f);
  131. make.right.mas_equalTo(-15.f);
  132. make.top.equalTo(_checUpdatekBtn.mas_bottom).offset(25.f);
  133. make.height.mas_equalTo(160.f);
  134. }];
  135. // UIButton *privateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  136. // self.privateBtn = privateBtn;
  137. // privateBtn.titleLabel.font = [UIFont systemFontOfSize:13.f];
  138. // [privateBtn setTitle:NSLocalizedString(@"app_update_private",nil) forState:UIControlStateNormal];
  139. // [privateBtn setTitleColor:HW13B2EBColor forState:UIControlStateNormal];
  140. // [privateBtn setBackgroundColor:[UIColor clearColor]];
  141. // [privateBtn addTarget:self action:@selector(privateBtnClick) forControlEvents:UIControlEventTouchUpInside];
  142. // privateBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  143. // [self.view addSubview:privateBtn];
  144. // [privateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  145. // make.bottom.mas_equalTo(-80-AdaptTabHeight);
  146. // //make.width.mas_equalTo(55);
  147. // make.width.mas_equalTo(130);
  148. // make.height.mas_equalTo(38);
  149. // make.left.equalTo(self.view.mas_centerX).offset(6);
  150. // }];
  151. //
  152. // UIButton *ruleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  153. // self.ruleBtn = ruleBtn;
  154. // ruleBtn.titleLabel.font = [UIFont systemFontOfSize:13.f];
  155. // [ruleBtn setTitle:NSLocalizedString(@"app_update_use_deal",nil) forState:UIControlStateNormal];
  156. // [ruleBtn setTitleColor:HW13B2EBColor forState:UIControlStateNormal];
  157. // [ruleBtn setBackgroundColor:[UIColor clearColor]];
  158. // [ruleBtn addTarget:self action:@selector(ruleBtnClick) forControlEvents:UIControlEventTouchUpInside];
  159. // ruleBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  160. // [self.view addSubview:ruleBtn];
  161. // [ruleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  162. // make.bottom.mas_equalTo(-80-AdaptTabHeight);
  163. // //make.width.mas_equalTo(55);
  164. // make.width.mas_equalTo(130);
  165. // make.height.mas_equalTo(38);
  166. // make.right.equalTo(self.view.mas_centerX).offset(-6);
  167. // }];
  168. //
  169. // UIView *lineView = [[UIView alloc] init];
  170. // [lineView setBackgroundColor:HW999999Color];
  171. // [self.view addSubview:lineView];
  172. // [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  173. // make.centerX.equalTo(self.view.mas_centerX);
  174. // make.width.mas_equalTo(1);
  175. // make.height.mas_equalTo(14);
  176. // make.centerY.equalTo(ruleBtn.mas_centerY);
  177. // }];
  178. }
  179. #pragma mark - 懒加载
  180. - (UITableView *)tableView{
  181. if (!_tableView) {
  182. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H - TABBARHEIGHT) style:UITableViewStylePlain];
  183. _tableView.delegate = self;
  184. _tableView.dataSource = self;
  185. _tableView.showsVerticalScrollIndicator = NO;
  186. _tableView.showsHorizontalScrollIndicator = NO;
  187. // _tableView.contentInset = UIEdgeInsetsMake(-H_STATE_BAR, 0, 0, 0);
  188. [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  189. [_tableView setSeparatorColor:[UIColor clearColor]];
  190. [_tableView setBackgroundColor:[UIColor whiteColor]];
  191. _tableView.layer.cornerRadius = 8;
  192. _tableView.scrollEnabled = NO;
  193. [_tableView setTableFooterView:[UIView new]];
  194. [_tableView setBounces:YES];
  195. if (@available(iOS 15.0, *)) {
  196. _tableView.sectionHeaderTopPadding = 0;
  197. }
  198. }
  199. return _tableView;
  200. }
  201. #pragma mark - 列表委托
  202. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  203. return 1;
  204. }
  205. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  206. return _msgTitleArr.count;
  207. }
  208. - (baseTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  209. __block NSInteger row = indexPath.row;
  210. static NSString *identifier = @"baseTableViewCell";
  211. baseTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  212. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  213. if (!cell){
  214. cell = [[baseTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  215. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  216. [cell setAccessoryType:(UITableViewCellAccessoryNone)];
  217. cell.showLeftImageType = NO;
  218. }
  219. //左边标题
  220. cell.showRightImageType = NO;
  221. if (row < _msgTitleArr.count) {
  222. NSString *title = _msgTitleArr[row];
  223. cell.titleLabel.text = title;
  224. if(row == 0){
  225. NSString *vers = [iPhone appVersion];
  226. [cell.contentLabel setText:[NSString stringWithFormat:@"V%@",vers]];
  227. }
  228. else if(_couldphoneSysInfoMod){
  229. cell.contentLabel.hidden = NO;
  230. if (row == 1) {
  231. cell.contentLabel.text = _couldphoneSysInfoMod.data.hostImgVer;
  232. }
  233. else if(row == 2) {
  234. cell.contentLabel.text = _couldphoneSysInfoMod.data.MyNewVersion;
  235. }
  236. }
  237. }
  238. return cell;
  239. }
  240. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  241. return 40;
  242. }
  243. - (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  244. return [UIView new];
  245. }
  246. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  247. return 20;
  248. }
  249. - (UIImage *)getAppIcon{
  250. NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
  251. //获取app中所有icon名字数组
  252. NSArray *iconsArr = infoDict[@"CFBundleIcons"][@"CFBundlePrimaryIcon"][@"CFBundleIconFiles"];
  253. //取最后一个icon的名字
  254. NSString *iconLastName = [iconsArr lastObject];
  255. //打印icon名字
  256. NSLog(@"iconsArr: %@", iconsArr);
  257. NSLog(@"iconLastName: %@", iconLastName);
  258. return [UIImage imageNamed:iconLastName];
  259. }
  260. #pragma mark- 网络请求
  261. - (void)getVersion {
  262. [self showNewIndicatorHaveStrWithCanBack:YES canTouch:NO showText:NSLocalizedString(@"app_update_checking",nil)];
  263. NSMutableDictionary *paraDict = [NSMutableDictionary dictionary];
  264. [paraDict setValue:@"ios" forKey:@"type"];
  265. [paraDict setValue:@"GBox" forKey:@"source"];
  266. [[netWorkManager shareInstance] CommonGetWithCallBackCode:upgradeNewVersion Parameters:paraDict success:^(id _Nonnull responseObject) {
  267. HLog(@"%@", responseObject);
  268. [self removeNewIndicatorHaveStr];
  269. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  270. if (model && model.status == 0) {
  271. HWVersionModel *model = [HWVersionModel mj_objectWithKeyValues:responseObject[@"data"]];
  272. self.versionModel = model;
  273. [self checkVersion];
  274. }
  275. else
  276. {
  277. //[[iToast makeText:model.msg] show];
  278. }
  279. } failure:^(NSError * _Nonnull error) {
  280. HLog(@"%@", error);
  281. [[iToast makeText:NSLocalizedString(@"player_link_fail_tip",nil)] show];
  282. [self removeNewIndicatorHaveStr];
  283. }];
  284. }
  285. - (void)versionCheckBtnClick {
  286. [self getVersion];
  287. }
  288. - (void)checkVersion {
  289. // NSString *currentVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleVersion"];
  290. NSString *currentVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"];
  291. NSString *newVersion = [self.versionModel.versionNumber stringByReplacingOccurrencesOfString:@"v" withString:@""]; //去掉v
  292. // HLog(@"%@---%@", newVersion, currentVersion);
  293. if ([currentVersion compare:newVersion options:NSNumericSearch] == NSOrderedSame) { // 本地版本号 == 服务器版本号
  294. // [self showNoNewVersion];
  295. //[self showNewVersion];
  296. [[iToast makeText:NSLocalizedString(@"app_update_last_version",nil)] show];
  297. [HWDataManager setBoolWithKey:Const_haveVersion value:NO];
  298. // _checUpdatekBtn.enabled = NO;
  299. // _checUpdatekBtn.backgroundColor = [UIColor hwColor:@"#959799" alpha:1.0];
  300. // [_gl_checkVersonBut removeFromSuperlayer];
  301. }else if ([currentVersion compare:newVersion options:NSNumericSearch] == NSOrderedDescending) { // 本地版本号 > 服务器版本号 (异常情况)
  302. [self showNoNewVersion];
  303. [HWDataManager setBoolWithKey:Const_haveVersion value:NO];
  304. // _checUpdatekBtn.enabled = NO;
  305. // _checUpdatekBtn.backgroundColor = [UIColor hwColor:@"#959799" alpha:1.0];
  306. // [_gl_checkVersonBut removeFromSuperlayer];
  307. }else { // 本地版本号 < 服务器版本号 (有新版本)
  308. self.versionModel.versionNumber = newVersion;
  309. [self showNewVersion];
  310. [HWDataManager setBoolWithKey:Const_haveVersion value:YES];
  311. };
  312. }
  313. - (void)showNewVersion {
  314. HaveNewVersionView *haveNewVersionView = [HaveNewVersionView shardInstance];
  315. if (haveNewVersionView.isShow) {
  316. return;
  317. }
  318. haveNewVersionView.versionModel = self.versionModel;
  319. haveNewVersionView.isContinueCheckAlert = NO; // 是否继续走下一步弹窗检测流程
  320. [haveNewVersionView setBackgroundColor:RGBACOLOR(0, 0, 0, 0.5)];
  321. [[[UIApplication sharedApplication] keyWindow] addSubview:haveNewVersionView];
  322. haveNewVersionView.isShow = YES;
  323. if(!self.versionModel.necessary){
  324. haveNewVersionView.deleteBtn.hidden = NO;
  325. }
  326. [haveNewVersionView mas_makeConstraints:^(MASConstraintMaker *make) {
  327. make.top.mas_equalTo(0);
  328. make.left.mas_equalTo(0);
  329. make.right.mas_equalTo(0);
  330. make.bottom.mas_equalTo(0);
  331. }];
  332. haveNewVersionView.alpha = 0.0;
  333. [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^ {
  334. haveNewVersionView.alpha = 1.0;
  335. KyoLog(@"in animate start");
  336. } completion:^(BOOL finished) {
  337. KyoLog(@"in animate completion");
  338. }];
  339. }
  340. - (void)showNoNewVersion {
  341. [[iToast makeText:NSLocalizedString(@"app_update_last_version",nil)] show];
  342. }
  343. - (void)ruleBtnClick {
  344. CustomerWebViewController *vc = [[CustomerWebViewController alloc] init];
  345. vc.titleStr = NSLocalizedString(@"app_update_use_deal",nil);
  346. NSString *url = @"";
  347. vc.webUrl = url;
  348. [self.navigationController pushViewController:vc animated:YES];
  349. }
  350. - (void)privateBtnClick {
  351. CustomerWebViewController *vc = [[CustomerWebViewController alloc] init];
  352. vc.titleStr = NSLocalizedString(@"app_update_private",nil);
  353. NSString *url = @"";
  354. vc.webUrl = url;
  355. [self.navigationController pushViewController:vc animated:YES];
  356. }
  357. - (void)didTap5NumFun
  358. {
  359. allVersionView *view = [[allVersionView alloc] init];
  360. UIWindow *keyWindow = [iTools getKeyWindow];
  361. [keyWindow addSubview:view];
  362. [view mas_makeConstraints:^(MASConstraintMaker *make) {
  363. make.top.mas_equalTo(0);
  364. make.left.mas_equalTo(0);
  365. make.right.mas_equalTo(0);
  366. make.bottom.mas_equalTo(0);
  367. }];
  368. if(_getSysInfo){
  369. _getSysInfo();
  370. }
  371. }
  372. - (void)getCouldPhoneBaseInfoFun:(NSNotification*)not
  373. {
  374. _couldphoneSysInfoMod = [not object];
  375. //HLog(@"%@",baseInfoModel);
  376. if(!_couldphoneSysInfoMod || ![_couldphoneSysInfoMod isKindOfClass:[couldphoneSysInfoModel class]]){
  377. return;
  378. }
  379. KWeakSelf
  380. mainBlock(^{
  381. [weakSelf.tableView reloadData];
  382. });
  383. }
  384. @end