//检查商店版本
+ (void)judgeAppStoreVersion{
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:New_version];//将需要升级版本号写入本地
[[NSUserDefaults standardUserDefaults] synchronize];
AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
NSString * kpath = @"http://itunes.apple.com/lookup?bundleId=项目的bundleID&country=cn";
[manager GET:kpath parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSDictionary *appInfo = (NSDictionary *)responseObject;
NSArray *infoContent = [appInfo objectForKey:@"results"];
NSString *version = [[infoContent objectAtIndex:0] objectForKey:@"version"];
if ([self compareVersionWithServiceVersion:version]) {
[[NSUserDefaults standardUserDefaults] setObject:version forKey:New_version];//将需要升级版本号写入本地
[[NSUserDefaults standardUserDefaults] synchronize];
[self alertUpdata];//提示用户需要升级
}else{
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:New_version];//将需要升级版本号写入本地
[[NSUserDefaults standardUserDefaults] synchronize];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"查询iTunes应用信息错误:%@",error.description);
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:New_version];//将需要升级版本号写入本地
[[NSUserDefaults standardUserDefaults] synchronize];
}];
}
//检查是都是最新版本
+ (BOOL)compareVersionWithServiceVersion:(NSString *)servierVersion{
NSLog(@"商店的版本是 %@",servierVersion);
NSArray * serviceArr = [servierVersion componentsSeparatedByString:@"."];
NSString * appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
NSLog(@"当前的版本是 %@",appVersion);
NSArray * appArr = [appVersion componentsSeparatedByString:@"."];
if (!serviceArr.count){
return NO;
}else{
NSInteger compare = 0;
if (serviceArr.count >= appArr.count) {
compare = appArr.count;
}else{
compare = serviceArr.count;
}
for (int i = 0; i < compare; i++) {
if ([serviceArr[i] integerValue] > [appArr[i] integerValue]) {
return YES;
}else if ([serviceArr[i] integerValue] == [appArr[i] integerValue]) {
continue;
}else{
return NO;
}
}
return NO;
}
}
//跳转App Store
+ (void)downLoadNewVersionJumpAppStore{
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"itms-apps://itunes.apple.com/app/id应用id"]];
}