下面是关于版本检测更新的介绍:
首先,我们要获得等待上传或正在写的app项目的版本号显示在view上
- NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
- CFShow((__bridge CFTypeRef)(infoDic));
- NSString *appVersion = [infoDic objectForKey:@"CFBundleVersion"];
然后我们要获得上个版本在app store 上的信息:
- //检查是否需要更新
- -(void)examineAppUpdate
- {
- NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
- //CFShow((__bridge CFTypeRef)(infoDic));
- NSString *currentVersion = [infoDic objectForKey:@"CFBundleVersion"];
- NSString *URL = @"http://itunes.apple.com/lookup?id=<span style="color:#cc33cc;">ID号</span>";
- 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];
- NSLog(@"dic = %@",dic);
然后我们通过json解析得到的数据为:
- );
- trackCensoredName = "\U6367\U8179\U7b11\U8bdd";
- trackContentRating = "17+";
- trackId = 493760196;
- trackName = "\U6367\U8179\U7b11\U8bdd";
- trackViewUrl = "https://itunes.apple.com/us/app/peng-fu-xiao-hua/id<span style="color:#ff0000;">APP的id</span>?mt=8&uo=4";
- userRatingCount = 5;
- userRatingCountForCurrentVersion = 3;
- version = "V1.08";
- wrapperType = software;
- }
我们就得到了我们要的app的信息,然后继上边的dic之后进行比较和操作:
- NSArray *infoArray = [dic objectForKey:@"results"];
- if ([infoArray count]) {
- NSDictionary *releaseInfo = [infoArray objectAtIndex:0];
- NSString *lastVersion = [releaseInfo objectForKey:@"version"];
- NSLog(@"%@",lastVersion);
- if (![lastVersion isEqualToString:currentVersion]) {
- //trackViewURL = [releaseInfo objectForKey:@"trackVireUrl"];
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"更新" message:@"有新的版本更新,是否前往更新?" delegate:self cancelButtonTitle:@"关闭" otherButtonTitles:@"更新", nil nil];
- alert.tag = 10000;
- [alert show];
- }
- else
- {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"更新" message:@"此版本为最新版本" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil nil];
- alert.tag = 10001;
- [alert show];
- }
- }
最后点击确定进入此app所在的app store上的页面:
- - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
- {
- if (alertView.tag==10000) {
- if (buttonIndex==1) {
- NSURL *url = [NSURL URLWithString:@"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=<span style="color:#cc0000;">app的ID</span>"];
- [[UIApplication sharedApplication]openURL:url];
- }
- }
- }