iphone - 如何使用 url 获取文件大小?
<p><div>
<aside class="s-notice s-notice__info post-notice js-post-notice mb16"role="status">
<div class="d-flex fd-column fw-nowrap">
<div class="d-flex fw-nowrap">
<div class="flex--item wmn0 fl1 lh-lg">
<div class="flex--item fl1 lh-lg">
<b>这个问题在这里已经有了答案</b>:
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>使用 <code>NSURLConnection</code> 和 <code>Head</code> 请求,响应将有 <a href="http://developer.apple.com/library/ios/#documentation/cocoa/reference/foundation/Classes/NSURLResponse_Class/Reference/Reference.html" rel="noreferrer noopener nofollow">expectedContentLength</a> :</p>
<p>请求</p>
<pre><code>NSMutableURLRequest * req = ];
;
NSURLConnection * con = [ initWithRequest:req
delegate:self];
;
;
</code></pre>
<p>委托(delegate)</p>
<pre><code>- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
NSLog(@"didReceiveResponse (%lld)", response.expectedContentLength);
}
</code></pre>
<p>注意它可能是负面的:</p>
<pre><code>#define NSURLResponseUnknownLength ((long long)-1)
</code></pre>
<p>对于 <code>NSURLSession</code>,使用接受 <code>NSURLRequest</code> 对象作为参数的任务工厂方法,例如<code>- (NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request completionHandler:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler:</code></p></p>
<p style="font-size: 20px;">关于iphone - 如何使用 url 获取文件大小?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/15920637/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/15920637/
</a>
</p>
页:
[1]