iOS App的版本检测更新功能(最新版)

今天是真正的想写一篇博客,以前都是工作忙没时间,所以从来没认真写过,就从今天起吧!

(由于上传突然断网,博主又重新谢了一遍....)

下面是关于版本检测更新的介绍:

首先,我们要获得等待上传或正在写的app项目的版本号显示在view上

 NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    CFShow((__bridge CFTypeRef)(infoDic));
    NSString *appVersion = [infoDic objectForKey:@"CFBundleVersion"];
我们得到的NSString就是版本号了


然后我们要获得上个版本在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];
            alert.tag = 10000;
            [alert show];
        }
        else
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"更新" message:@"此版本为最新版本" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: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];
        }
    }

}




  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值