zoukankan      html  css  js  c++  java
  • 开一个线程来处理 耗时的操作

    往往有很多操作会堵塞我们的UI这时候我们需要写一个线程来控制

    这是我们检查是否有新版本的更新时候 写的

     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{

            // 耗时的操作

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

            

            NSString *nowVersion = [infoDict objectForKey:@"CFBundleShortVersionString"];

            NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@", kStoreAppId]];

            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 range2 = NSMakeRange(substr.location+substr.length, substr2.location-substr.location-substr.length);

            NSString *newVersion =[file substringWithRange:range2];

            dispatch_async(dispatch_get_main_queue(), ^{

                NSLog(@"%@===vs====%@",nowVersion,newVersion);

                // 更新界面

                if(![nowVersion isEqualToString:newVersion])

                {

                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"版本有更新"delegate:self cancelButtonTitle:@"忽略"otherButtonTitles:@"更新",nil];

                     [alert show];

                }

            });

        });

  • 相关阅读:
    单词 统计
    第九周周进度报告
    日常总结
    Docker 初识
    读书笔记
    《未来简史》有感
    自己的Java规范文档
    nginx自动部署脚本
    jdk 自动化脚本
    我Java学习时的模样(三)
  • 原文地址:https://www.cnblogs.com/walkingzmz/p/5691570.html
Copyright © 2011-2022 走看看