开一个线程来处理 耗时的操作

 

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

            }

        });

    });

 

转载于:https://www.cnblogs.com/walkingzmz/p/5691570.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值