//从Appstore监测版本
-(void)onCheckVersion
{
//本地短版本号
NSDictionary *infoDic = [[NSBundlemainBundle] infoDictionary];
//CFShow((__bridge CFTypeRef)(infoDic));
NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
//itunes版本号
NSString *URL =@"http://itunes.apple.com/lookup?id=1102364142";
NSMutableURLRequest *request = [[NSMutableURLRequestalloc] init];
[request setURL:[NSURLURLWithString:URL]];
[request setHTTPMethod:@"POST"];
NSHTTPURLResponse *urlResponse = nil;
NSError *error = nil;
NSData *recervedData = [NSURLConnectionsendSynchronousRequest:request returningResponse:&urlResponse error:&error];
NSDictionary *dic = [NSJSONSerializationJSONObjectWithData:recervedData options:kNilOptionserror:&error];
NSArray *infoArray = [dic objectForKey:@"results"];
if ([infoArray count]) {
NSDictionary *releaseInfo = [infoArrayobjectAtIndex:0];
NSString *lastVersion = [releaseInfo objectForKey:@"version"];
if (![lastVersion isEqualToString:currentVersion]) {
UIAlertView *alert = [[UIAlertViewalloc] initWithTitle:@"更新"message:@"有新的版本更新,是否前往更新?"delegate:selfcancelButtonTitle:@"关闭"otherButtonTitles:@"更新",nil];
alert.tag = 10000;
[alert show];
}
}
}
//更新地址
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag==10000) {
if (buttonIndex==1) {
NSURL *url = [NSURLURLWithString:@"https://itunes.apple.com/us/app/coband/id1102364142?mt=8"];
下载地址类似:http://itunes.apple.com/app/id1166090758
[[UIApplicationsharedApplication]openURL:url];
}
}
}