在iOS 7中下载文件之前如何找到文件的大小? [英] How to find size of a file before downloading it in iOS 7?

查看:11
本文介绍了在iOS 7中下载文件之前如何找到文件的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想在 iOS 7 中下载文件之前在某个服务器上找到文件的大小...我有一个 NSURLConnectionDelegate 的方法,但它在 iOS 4.3 之后被弃用

Wanted to find size of a file on some server before downloading it in iOS 7... I have a method of NSURLConnectionDelegate but it is deprecated after iOS 4.3

这是那个方法:

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response

推荐答案

你应该改用 NSURLConnectionDataDelegate 注意:DATADelegate

You should instead use the NSURLConnectionDataDelegate Note: DATADelegate

及其didReceiveResponse:方法发送HEAD请求 只获取标题:

and its didReceiveResponse: method to send a HEAD request to get just the header:

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;

然后您可以通过@Port 的建议获得响应大小:

Then you can get the response size with @Port's suggestion:

long long size = [response expectedContentLength];

这篇关于在iOS 7中下载文件之前如何找到文件的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆