往往有很多操作会堵塞我们的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];

            }

        });

    });