复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69#pragma mark - 检查版本更新 +(void)checkVersion { // if (![self judgeNeedVersionUpdate]) { // return; // } NSString *localVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]; NSString *urlStr = @"https://itunes.apple.com/cn/lookup?id=xxx"; //xxx-你的Appid,iTunes可查看 [[HDNetworking sharedHDNetworking] GET:urlStr parameters:nil success:^(id _Nonnull responseObject) { int code = [responseObject[@"resultCount"] intValue]; if (code == 1) { NSArray *sourceArray = responseObject[@"results"]; if (sourceArray.count >= 1) { //AppStore内最新App的版本号 NSDictionary *sourceDict = sourceArray[0]; NSString *newVersion = sourceDict[@"version"]; if ([self judgeNewVersion:newVersion withOldVersion:localVersion]) { UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"版本更新" message:sourceDict[@"releaseNotes"] preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"暂不更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]; UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"去更新" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { //跳转到AppStore下载界面 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:sourceDict[@"trackViewUrl"]]]; }]; [alertVc addAction:action1]; [alertVc addAction:action2]; [[UIApplication sharedApplication].delegate.window.rootViewController presentViewController:alertVc animated:YES completion:nil]; } } } } failure:^(NSError * _Nonnull error) { }]; } //每天进行一次版本判断 - (BOOL)judgeNeedVersionUpdate { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM-dd"]; NSString *dateString = [formatter stringFromDate:[NSDate date]]; NSString *currentDate = [UserDefaultsUtils getCurrentDate]; if ([currentDate isEqualToString:dateString]) { return NO; } [UserDefaultsUtils setCurrentDate:dateString]; return YES; } /*! @brief 判断当前app版本和AppStore最新app版本大小 @param newVersion AppStore版本号 @param oldVersion 本地APP版本号 @return YES为AppStore版本大于本地APP版本 */ - (BOOL)judgeNewVersion:(NSString *)newVersion withOldVersion:(NSString *)oldVersion { NSArray *newArray = [newVersion componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"."]]; NSArray *oldArray = [oldVersion componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"."]]; if (oldArray.count == newArray.count) { for (NSInteger i = 0; i < newArray.count; i ++) { if ([newArray[i] integerValue] > [oldArray[i] integerValue]) { return YES; } else if ([newArray[i] integerValue] < [oldArray[i] integerValue]) { return NO; } } } return NO; }
最后
以上就是时尚小馒头最近收集整理的关于iOS 怎么在app里提示版本更新的全部内容,更多相关iOS内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复