dispatch_queue_t mainQueue =dispatch_get_main_queue();
dispatch_queue_t globalQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0);
NSDictionary *infoDic = [[NSBundlemainBundle] infoDictionary];
NSString *currentVersion = [infoDic objectForKey:@"CFBundleVersion"];
dispatch_async(globalQueue, ^{
NSString *URL =@"http://itunes.apple.com/lookup?id=你自己的AppID";
NSMutableURLRequest *request = [[NSMutableURLRequestalloc] init];
[requestsetURL:[NSURLURLWithString:URL]];
[requestsetHTTPMethod:@"POST"];
NSHTTPURLResponse *urlResponse = nil;
NSError *error = nil;
NSData *recervedData = [NSURLConnectionsendSynchronousRequest:request returningResponse:&urlResponse error:&error];
NSDictionary *dic = [NSJSONSerializationJSONObjectWithData:recervedData options:NSJSONReadingMutableContainerserror:&error];
NSArray *infoArray = [dic objectForKey:@"results"];
NSLog(@"%@", infoArray);
if ([infoArray count]) {
NSDictionary *releaseInfo = [infoArray objectAtIndex:0];
NSString *lastVersion = [releaseInfo objectForKey:@"version"];
if (![lastVersion isEqualToString:currentVersion]) {
dispatch_async(mainQueue, ^{
UIAlertView *alert = [[UIAlertViewalloc] initWithTitle:@"更新"message:@"有新的版本更新,是否前往更新?"delegate:selfcancelButtonTitle:@"关闭"otherButtonTitles:@"更新",nil];
alert.tag =10000;
[alertshow];
});
}
else
{
dispatch_async(mainQueue, ^{
UIAlertView *alert = [[UIAlertViewalloc] initWithTitle:@"更新"message:@"此版本为最新版本"delegate:selfcancelButtonTitle:@"确定"otherButtonTitles:nil,nil];
alert.tag =10001;
[alertshow];
});
}
}
});
}
这个代码是连接更新的地址
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag==10000) {
if (buttonIndex==1) {
NSURL *url = [NSURLURLWithString:@"https://itunes.apple.com/cn/app/ji-xun-xin-wen/id962735629?mt=8"];(这里填写的是你自己的App的连接)
[[UIApplicationsharedApplication]openURL:url];
}
}
}