sinat_33800566
小蜗牛2016
2016-01-21 22:03

IOS9之后,怎么通过URL从网络上下载数据,具体方法?

  • ios

-(void)downloadWithUrl:(NSURL *)url compelet:(DownLoadBlock)block {
//保存block
self.block = block;
//创建队列
dispatch_queue_t queue = dispatch_queue_create(nil, DISPATCH_QUEUE_CONCURRENT);
dispatch_async(queue, ^{

    //执行下载任务
    //创建请求
    NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];
    //获取数据
    NSData *date = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
//将数据返回给调用者
    dispatch_sync(dispatch_get_main_queue(), ^{

        self.block(date);


    });

});

}
获取数据的方法好像是ios9.0之后就不能用了,现在怎么获取,

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答