如何在iOS 7中下载之前查找文件的大小? [英] How to find size of a file before downloading it in iOS 7?
本文介绍了如何在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请求以获取标题:
- (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屋!
查看全文