URL地址: https://itunes.apple.com/cn/lookup?id=你的AppId
參數AppId指的是你在APP在創建后的唯一標識,在iTunes Connect里可以查找到此信息。
tmp58d9db39.png
獲取線上版本信息(字段---version)
//獲取當前bundle中的版本號
NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
//獲取App Store中當前APP的版本號
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager POST:urlStr parameters:nil success:^(AFHTTPRequestOperation * _Nonnull operation, id _Nonnull responseObject) {
NSArray *array = responseObject[@"results"];
NSDictionary *dict = [array lastObject];
NSLog(@"線上版本:%@", dict[@"version"]);
NSString *lineVersion = dict[@"version"];
if ([lineVersion compare:currentVersion options:NSNumericSearch] == NSOrderedDescending)
{
//appstore 版本更高
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message: [NSString stringWithFormat:@" 新版本 %@ 已發布 ! ", lineVersion] delegate:self cancelButtonTitle:@"以后再說" otherButtonTitles: @"馬上更新", nil];
[alert show];
NSLog(@"線上版本:%@ 更高", lineVersion);
}
else
{
NSLog(@"當前版本:%@ 更高", currentVersion);
}
//返回json中的trackViewUrl就是App Store中當前APP的下載頁面
self.trackViewUrl = dict[@"trackViewUrl"];
} failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
NSLog(@"錯誤 : %@",error);
}];
//跳轉App Store頁面進行下載
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:self.trackViewUrl]];