zoukankan      html  css  js  c++  java
  • iOS检测版本更新

    有时候为了需求,我们需要检测app版本更新今天在这里整合下

    //获取当前版本号

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

        CFShow((__bridge CFTypeRef)(infoDictionary));

        

        NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];

        //获取苹果商店的版本号

        NSError  *error;

        NSString * urlStr = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=你要检测的app版本"];

        NSURL * url =[NSURL URLWithString:urlStr];

        NSURLRequest * request =[NSURLRequest requestWithURL:url];

        NSData * response =[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

        NSDictionary * appInfo =[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];

        if (error) {

            NSLog(@"error:%@",[error description]);

        }

        NSArray *resultsArray =[appInfo objectForKey:@"results"];

        if (![resultsArray count]) {

            NSLog( @"error: nil");

            return self;

        }

        NSDictionary * infoDic =[resultsArray objectAtIndex:0];

        NSString * appVersion = [infoDic objectForKey:@"version"];

       appUrl =[infoDic objectForKey:@"trackViewUrl"];

        double doucurrV =[app_Version doubleValue];

        double  douappV= [appVersion doubleValue];

        //判断版本号对比

        if (doucurrV < douappV) {

            NSString * titleStr =[NSString stringWithFormat:@"检查更新"];

            NSString * message =[NSString stringWithFormat:@"发现新版本,是否更新?"];

            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:titleStr message:message delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

            

            alert.tag = 1001;

            [alert show];

                                  

        }else

        {

            

            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"检测更新" message:@"无更新版本"delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

            

            alert.tag = 1002;

            [alert show];

            

            

        }

       //跳转更新 

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

    {

        

        if (alertView.tag ==1001) {

            if (buttonIndex == 1) {

                [[UIApplication sharedApplication]openURL:[NSURL URLWithString: appUrl]];

            }

        }

        

    }

  • 相关阅读:
    如何把自己的百度网盘的内容分享给别人
    postman 中post方式提交数据
    在ThinkPHP中,if标签和比较标签对于变量的比较。
    Linux SVN搭建模式 规格严格
    Redmine安装201209 规格严格
    GBK 规格严格
    MySQL分区优化 规格严格
    Null 规格严格
    Compiler 规格严格
    UDP VS TCP 规格严格
  • 原文地址:https://www.cnblogs.com/LGX3399577/p/re1.html
Copyright © 2011-2022 走看看