我想你應該嘗試的用戶NSURLMutableRequest相反在下載大文件,這樣你就可以得到多部分下載的情況。您也可以使用NSURLResponse的expectedContentLength方法來了解文件長度。下面是一個例子:
- (void)connection:(NSURLConnection *)connection
didReceiveResponse:(NSURLResponse *)響應{
NSLog (@"%d", [response expectedContentLength]);
}
- (void)connection:(NSURLConnection *)connection
didReceiveData:(NSData *)data {
if (self.currentDownloadedFile) {
[self.currentDownloadedFile seekToEndOfFile];
[self.currentDownloadedFile writeData:data];
}
}
- (void)connectionDidFinishLoading:(NSURLConnection*)connection {
// Close the file here
}
並強制UIWebView打開下載的文件,而不是從un URL下載。