zoukankan      html  css  js  c++  java
  • NSData的同步下载与NSConnection的同步下载

    NSData 同步下载

        NSString * path = @"http://10.0.100.8/sns/my/user_list.php";
        
        //转网址对象
        NSURL * url = [NSURL URLWithString:path];
        
        //转Data
        NSData * data = [NSData dataWithContentsOfURL:url];
        
        if (data) {
             id obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            //这是一个同步请求  请求和响应在一起
            NSLog(@"%@",obj);
        }
        
        //同步下载会堵塞线程  主线程 --- 显示UI
        
        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"进入主界面" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        
        [alert show];

    NSConnection 同步下载

     

        NSString * path = @"http://10.0.100.8/sns/my/user_list.php";
        
        //转网址对象
        NSURL * url = [NSURL URLWithString:path];
        
        //转Data
        NSData * data = [NSData dataWithContentsOfURL:url];
        
        if (data) {
             id obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            //这是一个同步请求  请求和响应一气呵成
            NSLog(@"%@",obj);
        }
        
        //同步下载会堵塞线程  主线程 --- 显示UI
        
        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"进入主界面" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        
        [alert show];

     

  • 相关阅读:
    IntelliJ IDEA 2020.1.1中java web项目的配置
    Js查漏补缺10-数组、栈、队列、回调函数等
    Js查漏补缺09-this对象
    Js查漏补缺08-闭包
    Js查漏补缺07-匿名函数应用到的框架
    Js查漏补缺06-匿名函数的用法
    Js查漏补缺05-函数
    Js查漏补缺04-Object类型
    Js查漏补缺03-循环结构
    Runnabler
  • 原文地址:https://www.cnblogs.com/konglei/p/4830549.html
Copyright © 2011-2022 走看看