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

    //版本检测

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

        NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];

        NSURL *url = [NSURL URLWithString:@"http://itunes.apple.com/lookup?id=1602294206"];

        

        NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:0 timeoutInterval:15];

        NSURLSession *session = [NSURLSession sharedSession];

        

        NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {

            

            if (error) {

    //            //初始化提示框;

    //            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"请链接网络" preferredStyle: UIAlertControllerStyleAlert];

    //            [alert addAction:[UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

    //            }]];

    //            //弹出提示框;

    //            [self presentViewController:alert animated:true completion:nil];

                return ;

            }

            

            id obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];

              NSLog(@"-----%@",obj);

            NSArray *infoArray = [obj objectForKey:@"results"];

            if ([infoArray count]) {

                NSDictionary *relaseInfo = [infoArray objectAtIndex:0];

                

                NSString *lastVersion = [relaseInfo objectForKey:@"version"];

                NSString *urlstr = [relaseInfo objectForKey:@"trackViewUrl"];

              

                if (![lastVersion isEqualToString:currentVersion]) {

                    

                    //初始化提示框;

                    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"检测到新版本" preferredStyle: UIAlertControllerStyleAlert];

                    [alert addAction:[UIAlertAction actionWithTitle:@"立即更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

                        NSURL *url = [NSURL URLWithString:urlstr];

                        [[UIApplication sharedApplication]openURL:url];

                        

                    }]];

                    [alert addAction:[UIAlertAction actionWithTitle:@"稍后提醒" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

                    }]];

                    

                    //弹出提示框;

                    [self presentViewController:alert animated:true completion:nil];

                    

                }

            }

            

        }];

        [task resume];

  • 相关阅读:
    sql处理数据库锁的存储过程
    SQL语句
    partial 函数
    map函数
    python命令行上下 退格,左右键不能用
    postgresql 在linux上的源码安装
    python字典操作
    根据key存不存在查询json
    精典博文
    python解析XML之ElementTree
  • 原文地址:https://www.cnblogs.com/lcl15/p/5427857.html
Copyright © 2011-2022 走看看