URL地址: https://itunes.apple.com/cn/lookup?id=你的AppId
参数AppId指的是你在APP在创建后的唯一标识,在iTunes Connect里可以查找到此信息。
获取线上版本信息(字段---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]];
网友评论