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]];

            }

        }

        

    }

  • 相关阅读:
    希尔排序的理解和实现(Java)
    直接插入排序实现(Java)
    冒泡排序算法与选择排序算法
    Java中IO流中所涉及到的各类方法介绍
    Java常见编码方式简介
    Java中的BufferedReader 的readLine方法
    Java使用基本字节流OutputStream的四种方式对于数据复制(文本,音视频,图像等数据)
    java中IO流操作的标准异常类
    Java中常见数据结构:list与map
    互联网的网络地址分类
  • 原文地址:https://www.cnblogs.com/LGX3399577/p/re1.html
Copyright © 2011-2022 走看看