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

                }

            });

        });

  • 相关阅读:
    HDU 2236 无题II
    P2220 [HAOI2012]容易题
    UVA11383 Golden Tiger Claw
    AT2272 [ARC066B] Xor Sum
    CentOS7 静默安装oracle12c
    SNAT与DNAT
    Linux下离线安装Docker
    TJOI2017 DNA 和 BJOI2015 隐身术
    LOJ6169 相似序列
    BJOI2019 删数
  • 原文地址:https://www.cnblogs.com/walkingzmz/p/5691570.html
Copyright © 2011-2022 走看看