获取当前版本号
NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
//CFShow((__bridge CFTypeRef)(infoDic));
NSString *currentVersion = [infoDic objectForKey:@"CFBundleVersion"];
//获取AppStore中版本号
NSString *appStoreVersion = [[NSString alloc] init];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
// id=414478124 是AppStore中应用的ID
[manager POST:@"http://itunes.apple.com/lookup?id=414478124" parameters:nil success:^(AFHTTPRequestOperation * _Nonnull operation, id _Nonnull responseObject) {
NSArray *array = responseObject[@"results"];
NSDictionary *dict = [array lastObject];
NSLog(@"当前版本为:%@", dict[@"version"]);
appStoreVersion = [dict objectForKey:@"version"];
} failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
[SVProgressHUD showErrorWithStatus:@"请求失败!" ];
}];
版本对比
if (![appStoreVersion isEqualToString:currentVersion]) {
//trackViewURL = [releaseInfo objectForKey:@"trackVireUrl"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"更新" message:@"有新的版本更新,是否前往更新?"delegate:self cancelButtonTitle:@"关闭" otherButtonTitles:@"更新", nil];
alert.tag = 10000;
[alert show];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"更新" message:@"此版本为最新版本" delegate:selfcancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
alert.tag = 10001;
[alert show];
}
//alert 上button点击方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag==10000) {
if (buttonIndex==1) {
NSURL *url = [NSURL URLWithString:@"https://itunes.apple.com"];
[[UIApplication sharedApplication]openURL:url];
}
}
}
{
resultCount = 1;
results = (
{
artistId = 开发者 ID;
artistName = 开发者名称;
price = 0;
isGameCenterEnabled = 0;
kind = software;
languageCodesISO2A = (
EN
);
trackCensoredName = 审查名称;
trackContentRating = 评级;
trackId = 应用程序 ID;
trackName = 应用程序名称";
trackViewUrl = 应用程序介绍网址;
userRatingCount = 用户评级;
userRatingCountForCurrentVersion = 1;
version = 版本号;
wrapperType = software;
}
);
}
如果你拷贝 trackViewUrl 的实际地址,然后在浏览器中打开,就会打开你的应用程序在 appstore 中的介绍页面。当然我们也可以在代码中调用 safari 来打开它。
UIApplication *application = [UIApplication sharedApplication];
[application openURL:[NSURL URLWithString:trackViewUrl]];