码迷,mamicode.com
首页 > 编程语言 > 详细

线程间通信

时间:2015-09-24 00:44:08      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:

  //创建url
    NSURL *url = [NSURL URLWithString:str];
    //创建请求
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    //发送请求
//    NSOperationQueue *queue = [NSOperationQueue mainQueue];
    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        NSLog(@"%@",[NSThread currentThread]);
        //JSON解析
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
        if (dict[@"success"]) {
            //回到主线程显示
            dispatch_async(dispatch_get_main_queue(), ^{
                 [MBProgressHUD showError:dict[@"success"]];
            });
         
        }else
        {
            // NSOperationQueue *queue = [[NSOperationQueue alloc] init];如果来到这,会卡死在子线程
            [MBProgressHUD showError:@"!"];
        }

        

线程间通信

标签:

原文地址:http://www.cnblogs.com/hl-iOS/p/4834008.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!