版本号 一般采用 x.x.x 的形式
1 第一位 代表 主版本号 。 出现某些重大更新和bug 不更新严重影响用户体验时候使用 (强制更新)
2 第二位 代表 功能版本号 。 添加新功能模块
3 第三位 为 修订版本号 。 常规优化和修复小bug
获取APP商店的信息
WS(ws);
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager GET:[CJAppInfo appUrlInItunes] parameters:**nil** headers:**nil** progress:^(NSProgress * **_Nonnull** downloadProgress) {
} success:^(NSURLSessionDataTask * **_Nonnull** task, **id** **_Nullable** responseObject) {
DLog(@"%@",responseObject);
//请求成功?
**if** (((NSArray *)responseObject[@"results"]).count<=0) {
**return**;
}
// 获取trackId
ws.trackId = [(NSArray *)responseObject[@"results"] firstObject][@"trackId"];
// DLog(@"trackId ==== %@",self.trackId);
//获取appstore版本号和提示信息
ws.storeVersion = [(NSArray *)responseObject[@"results"] firstObject][@"version"];
NSString *releaseNotes = [(NSArray *)responseObject[@"results"] firstObject][@"releaseNotes"];
//获取跳过的版本号
NSString *skipVersion = [[NSUserDefaults standardUserDefaults] valueForKey:skipVersionKey];
//比较版本号
DLog(@"%@--%@",**self**.storeVersion,skipVersion);
**if** ([ws.storeVersion isEqualToString:skipVersion]) {//如果store和跳过的版本相同
**return**;
}**else**{
[ws compareCurrentVersion:[CJAppInfo appVersion] withAppStoreVersion:**self**.storeVersion updateMsg:releaseNotes];
}
} failure:^(NSURLSessionDataTask * **_Nullable** task, NSError * **_Nonnull** error) {
}];
对比版本
NSMutableArray *currentVersionArr = [[currentVersion componentsSeparatedByString:@"."] mutableCopy];
NSMutableArray *appStoreVersionArr = [[appStoreVersion componentsSeparatedByString:@"."] mutableCopy];
**if** (!currentVersionArr.count ||!appStoreVersionArr.count){
**return**;
}
**int** mendCount = abs((**int**)(currentVersionArr.count - appStoreVersionArr.count));
// 补全 3位版本号 不足 补0
**if** (currentVersionArr.count > appStoreVersionArr.count) {
**for** (**int** index = 0; index < mendCount; index ++) {
[appStoreVersionArr addObject:@"0"];
}
} **else** **if** (currentVersionArr.count < appStoreVersionArr.count) {
**for** (**int** index = 0; index < mendCount; index ++) {
[currentVersionArr addObject:@"0"];
}
}
//强制更新
**if** ([currentVersionArr.firstObject integerValue] < [appStoreVersionArr.firstObject integerValue]) {
[**self** showUpdateAlertMust:**YES** withStoreVersion:appStoreVersion message:updateMsg];
}**else**{
//提示更新
**for** (**int** index = 0; index<currentVersionArr.count; index++) {
**if** ([currentVersionArr[index] integerValue] < [appStoreVersionArr[index] integerValue]) {
[**self** showUpdateAlertMust:**NO** withStoreVersion:appStoreVersion message:updateMsg];
**return**;
}
}
}
提示更新 不考虑ios 8.0 以前的系统 ,使用 UIAlertController 进行提示
跳转APP 执行更新
NSURL *trackUrl = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/cn/app/id%@",self.trackId]];
if ([[UIApplication sharedApplication] canOpenURL:trackUrl]) {
[[UIApplication sharedApplication] openURL:trackUrl];
}
使用
- (void)applicationDidBecomeActive:(UIApplication *)application {
[[CJCheckVersion shareCheckVersion] checkVersion];
}
[APP跳转商店参考]www.jianshu.com/p/010ba9153…