网络---小文件的下载

来源:互联网 发布:大数据法律法规 编辑:程序博客网 时间:2024/05/01 10:55

在实际开发过程中,经常会遇到文件的下载操作,接下来就介绍一下文件下载的操作


方法:

a> 使用 [NSData dataWithContentsOfURL

dispatch_async(dispatch_get_global_queue(0, 0), ^{                NSURL *url = [NSURL URLWithString:@"下载地址”];        NSData *data = [NSData dataWithContentsOfURL:url];        NSLog(@"%d", data.length);    });


b> NSURLConnection

NSURL *url = [NSURL URLWithString:@"下载地址"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {        NSLog(@"%d", data.length);    }];




0 0
原创粉丝点击