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

            }

        }

        

    }

  • 相关阅读:
    【C#进阶】override new virtual
    【小窍门】cmd控制台无法输入中文(日文),输出非英文字符都是问号解决办法,中文都是问号解决办法
    【C#进阶】多播委托和委托数组像是一回事~
    【C# 基础应用】我的第一个App,不容易——随机生成小人网站,asp.net core
    【Xpath学习】xpath都不会,说什么你做网站自动化测试的?
    【Python + Selenium】Mock Testing 是啥?一个so上的高票答案。
    【Python】 Subprocess module
    【selenium 3】 Mac 下测试环境搭建 Firefox 47+ gecko driver Mac
    关于boost 的smart_ptr 的使用问题
    UI自动化测试的那些事
  • 原文地址:https://www.cnblogs.com/LGX3399577/p/re1.html
Copyright © 2011-2022 走看看