• 版本更新


    //版本检测

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

  • 相关阅读:
    matplotlib数据可视化之柱形图
    xpath排坑记
    Leetcode 100. 相同的树
    Leetcode 173. 二叉搜索树迭代器
    Leetcode 199. 二叉树的右视图
    Leetcode 102. 二叉树的层次遍历
    Leetcode 96. 不同的二叉搜索树
    Leetcode 700. 二叉搜索树中的搜索
    Leetcode 2. Add Two Numbers
    Leetcode 235. Lowest Common Ancestor of a Binary Search Tree
  • 原文地址:https://www.cnblogs.com/lcl15/p/5427857.html
Copyright © 2020-2023  润新知