版本更新

-(void)onCheckVersion

{

NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];

NSString *currentVersion = [infoDic objectForKey:@"CFBundleVersion"];

NSString *URL = @"http://itunes.apple.com/lookup?id=946712292";

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

[request setURL:[NSURL URLWithString:URL]];

[request setHTTPMethod:@"POST"];

NSHTTPURLResponse *urlResponse = nil;

NSError *error = nil;

NSData *recervedData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];

NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:recervedData options:NSJSONReadingMutableContainers error:nil];

NSArray *infoArray = [dic objectForKey:@"results"];

if ([infoArray count]) {

NSDictionary *releaseInfo = [infoArray objectAtIndex:0];

NSString *lastVersion = [releaseInfo objectForKey:@"version"];

if (![lastVersion isEqualToString:currentVersion]) {

//trackViewURL = [releaseInfo objectForKey:@"trackVireUrl"];

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"更新" message:@"有新的版本更新,是否前往更新?" delegate:self cancelButtonTitle:@"关闭" otherButtonTitles:@"更新", nil];

alert.tag = 10200;

[alert show];

}

else

{

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"更新" message:@"此版本为最新版本" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

alert.tag = 10201;

[alert show];

}

}

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

if (alertView.tag==10200) {

if (buttonIndex==1) {

NSURL *url =[NSURL URLWithString:@"https://itunes.apple.com/cn/app/ri-shi-qing-ri-cheng-ri-ji/id946712292?mt=8"];

[[UIApplication sharedApplication]openURL:url];

}

}

}

你可能感兴趣的:(版本更新)