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];

     

  • 相关阅读:
    eclipse javaWeb项目如何引入jar包
    Unity3D 批量图片资源导入设置
    WaitForTargetFPS
    自适应分辨率
    UnityException: Texture is not readable
    Unity bundle的制作和使用
    Unity3D之Assetbundle
    Unity使用外部版本控制SVN
    AssetBundle机制相关资料收集
    Assetbundle的杂七杂八
  • 原文地址:https://www.cnblogs.com/konglei/p/4830549.html
Copyright © 2011-2022 走看看