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

            }

        }

        

    }

  • 相关阅读:
    sessionStorage用于分页,瀑布流和存储用户数据等
    js瀑布流
    sql 日结
    js 去除html标签
    c# 去除文本的html标签
    jQuery 数据滚动(上下)
    jQuery 图片随滚动条滚动加载
    sql 指定范围 获取随机数
    js 时间格式化
    js自写字符串 append 方法
  • 原文地址:https://www.cnblogs.com/LGX3399577/p/re1.html
Copyright © 2011-2022 走看看