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

    检测版本更新的方法。

      //检查新版本 更新
        
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            // 耗时的操作
            
            //获取本地版本号
            NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
            NSString *version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
            NSString *build = [infoDictionary objectForKey:@"CFBundleVersion"];
            NSString *nowVersion = [NSString stringWithFormat:@"%@.%@", version, build];
            
            //获取appStore网络版本号
            NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@", @"1081299934"]];
            NSString * file =  [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
            
            NSRange substr = [file rangeOfString:@""version":""];
            NSRange range1 = NSMakeRange(substr.location+substr.length,10);
            //    NSRange substr2 =[file rangeOfString:@""" options:nil range:range1];
            NSRange substr2 = [file rangeOfString:@""" options:NSCaseInsensitiveSearch  range:range1];
            NSRange range2 = NSMakeRange(substr.location+substr.length, substr2.location-substr.location-substr.length);
            NSString *appStoreVersion =[file substringWithRange:range2];
            
            dispatch_async(dispatch_get_main_queue(), ^{
                // 更新界面
                
                //如果不一样去更新
                if(![nowVersion isEqualToString:appStoreVersion])
                {
                    
                    [self showAlert];
                    
                }
                
                
            });
        });
    
    
    /**
     *  检查新版本更新
     */
    -(void)showAlert
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"有新的版本啦~~" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"前去更新",nil];
        [alert show];
    
    }
    
    - (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    {
        if(buttonIndex==1)
        {
            // 此处加入应用在app store的地址,方便用户去更新,一种实现方式如下:
            NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/us/app/id%@?ls=1&mt=8", @"10812999054"]];
            [[UIApplication sharedApplication] openURL:url];
        }
    }
  • 相关阅读:
    ubuntu16.04配置网卡
    如何让虚拟机的Ubuntu上网?
    sqlite错误 The database disk image is malformed database disk image is malformed 可解决
    Linux系统安装bcompare步骤及注意事项Linux系统安装bcompare步骤及注意事项
    用python做科学计算(一)C语言读取python生成的二进制文件
    ubuntu下的RapidSVN
    matplotlib常见问题总结
    MATLAB中的矩阵索引
    4.0 Lab1-CRC Generation(1)
    项目管理-人员配置
  • 原文地址:https://www.cnblogs.com/OIMM/p/8916116.html
Copyright © 2011-2022 走看看