1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| NSError *error; NSString *urlStr = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@",appID]; NSURL *url = [NSURL URLWithString:urlStr]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; NSDictionary *appInfoDic = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error]; if (error) { MMLog(@"error:%@",[error description]); [MMHUD HUD:@"暂无更新"]; return; } NSArray *resultsArray = [appInfoDic objectForKey:@"results"]; if (![resultsArray count]) { MMLog(@"error:resultsArray == nil"); [MMHUD HUD:@"暂无更新"]; return; } NSDictionary *infoDic = [resultsArray objectAtIndex:0]; NSString *latestVersion = [infoDic objectForKey:@"version"]; _trackViewUrl = [infoDic objectForKey:@"trackViewUrl"]; NSString *trackName = [infoDic objectForKey:@"trackName"]; NSDictionary *infodict = [[NSBundle mainBundle] infoDictionary]; NSString *currentVersion = [infodict objectForKey:@"CFBundleVersion"]; double doubleCurrentVersion = [currentVersion doubleValue]; double doubleupdateVersion = [latestVersion doubleValue]; MMLog(@"%@",currentVersion); if (doubleCurrentVersion < doubleupdateVersion) { NSString *titleStr = [NSString stringWithFormat:@"检查更新:%@",trackName]; NSString *messageStr = [NSString stringWithFormat:@"发现新版本(%@),是否更新",latestVersion]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:titleStr message:messageStr delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"升级", nil]; alert.tag = 1; [alert show]; }else{ NSString *titleStr = [NSString stringWithFormat:@"检查更新:%@",trackName]; NSString *messageStr = [NSString stringWithFormat:@"暂无新版本"]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:titleStr message:messageStr delegate:self cancelButtonTitle:@"好的" otherButtonTitles:nil, nil]; alert.tag = 2; [alert show]; }
#pragma mark - alertviewshow
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ if (alertView.tag == 1) { MMLog(@"直接请求appurl"); [[UIApplication sharedApplication] openURL:[NSURL URLWithString:_trackViewUrl]]; } }
|