#pragma mark - 检查更新
- (void)checkVersion
{
if ([AppID length] < 1) {
return;
}
NSString *url = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@",AppID];
NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] init];
[urlRequest setURL:[NSURL URLWithString:url]];
[urlRequest setHTTPMethod:@"POST"];
NSData *returnData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:nil error:nil];
NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:returnData options:0 error:nil];
NSArray *infoArr = [jsonDic objectForKey:@"results"];
if ([infoArr count]) {
NSDictionary *releaseInfo = [infoArr objectAtIndex:0];
NSString *appStoreVersion = [releaseInfo objectForKey:@"version"];
// 这里显示的是appstore 上面设置的号码.
NSLog(@"appstore 版本为:%@ \n 当前版本为:%@",appStoreVersion,VERSION);
if ([VERSION compare: appStoreVersion] == NSOrderedAscending) {
// 弹窗
NSArray *items = @[MMItemMake(@"立即更新", MMItemTypeHighlight, ^(NSInteger index) {
NSURL *url = [NSURL URLWithString:DownloadUrl];
NSLog(@"跳转下载地址 : %@", DownloadUrl);
[[UIApplication sharedApplication] openURL:url];
}),MMItemMake(@"稍后提醒", MMItemTypeNormal, nil)];
[[[MMAlertView alloc] initWithTitle:@"提示" detail:@"出新版本啦,快点更新吧!" items:items]showWithBlock:nil];
}
}
}
版权声明:本文为johnay_xiao原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。