2012-08-02 76 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