NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
NSString *currentVersion = [infoDict objectForKey:@"CFBundleVersion"];
double doubleCurrentVersion = [currentVersion doubleValue];
NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://itunes.apple.com/lookup?id=你的appid"]];
AFHTTPRequestOperation *request = [[AFHTTPRequestOperation alloc] initWithRequest:req];
[request setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSString *str=[[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSDictionary *jsonData = [NSJSONSerialization JSONObjectWithData:[str dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:nil];
NSLog(@"%@",jsonData);
NSArray *infoArray = [jsonData objectForKey:@"results"];
if (infoArray.count!=0) {
NSDictionary *releaseInfo = [infoArray objectAtIndex:0];
NSString *latestVersion = [releaseInfo objectForKey:@"version"];
NSString *trackViewUrl = [releaseInfo objectForKey:@"trackViewUrl"];
_updateUrl = trackViewUrl;
double updateVersion = [latestVersion doubleValue];
if (updateVersion > doubleCurrentVersion) {
UIAlertView *alertd = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"检测到有新版本,立即前往更新?" delegate:self cancelButtonTitle:@"暂不更新" otherButtonTitles:@"立即前往", nil];
alertd.tag = 110;
[alertd show];
}else
{
// [[[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"当前已是最新版本" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil] show];
}
}else{
// [[[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"当前已是最新版本" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil] show];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// [self errorActionWith:error];
}];
[request start];
}