zoukankan      html  css  js  c++  java
  • 线程间通信

      //创建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:@"!"];
            }

            

  • 相关阅读:
    ORACLE CLIENT客户端安装步骤详解
    mkswap 把一个分区格式化成为swap交换区
    编译安装lnmp
    使用源代码安装lnmp
    查看nginx编译安装
    linux lnmp编译安装
    nginx编译安装
    lnmp脚本
    搭建LAMP测试环境
    绝路上的桥
  • 原文地址:https://www.cnblogs.com/hl-iOS/p/4834008.html
Copyright © 2011-2022 走看看