2012-08-02 89 views
0

我正在从网上下载文件。当我重新开始下载文件时,它会从起点再次重启,而不是从暂停下载的位置重新开始。在我暂停下载的时候,我保存了下载文件的值。但现在我无法如何恢复已暂停的文件的下载。 我使用此代码来下载新文件使用ASIHTTPRequest恢复下载

 url = [NSURL URLWithString:_item.link]; 
    _receivedBytes = 0; 
    _speed = 0; 
    _lastTime = [[NSDate date] timeIntervalSince1970]; 
    _connection = [ASIWebPageRequest requestWithURL:url]; 
    [_connection setUrlReplacementMode:ASIReplaceExternalResourcesWithData]; 
    [_connection setDelegate: self]; 
    [_connection setDownloadProgressDelegate:self]; 
    [_connection setDownloadCache:[ASIDownloadCache sharedCache]]; 
    [_connection setDownloadDestinationPath: _item.path]; 
    [_connection startAsynchronous]; 

回答

0

按照ASIHTTPRequest文档断点续传只有当你直接下载到文件的工作。

我假设你下载到内存中(因为你使用的是_receivedBytes)。通过设置

ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; 
[request setTemporaryFileDownloadPath:@"/path/to/tempfolder/yourfile.jpg.download"]; 
[request setDownloadDestinationPath:@"/path/to/final/destination/yourfile.jpg"]; 

然后你就可以使中断的下载的断点续传:

如果要存储下载的文件到设备的文件系统,无论如何,你可以直接使用下载到文件系统

[request setAllowResumeForFileDownloads:YES]; 

你会发现更多的细节here

+0

我已经改变了它ASIHTTPRequest,但是当我重新开始下载,进度视图中再次从零字节开始。 – 2012-08-02 08:57:10

+0

您是否按照ASIHTTPRequest文档“恢复中断的下载”中的说明实现了它? – joern 2012-08-02 08:59:40

+0

恢复下载的代码是 – 2012-08-02 09:03:12