2011-06-20 84 views
0

我已經得到了類同這個帖子ASIHTTP asynchrounous pdf downloadASIHttpRequest繼續下載

我會用setTemporaryFileDownloadPath恢復下載的問題:但奇怪的是,當我叫setDelegate自我和異步啓動連接,緩存韓元不要將它保存到temporaryFileDownloadPath中,而是要重新設置委託,緩存將保存到路徑中。

_conn = [[ASIHTTPRequest alloc] initWithURL:_currentURL]; 
    [_conn setDownloadDestinationPath:_currentFileNameWithPath]; 
    [_conn setTemporaryFileDownloadPath:tempPdfLocation];  
    [_conn setAllowResumeForFileDownloads:YES]; 
    //[_conn setDelegate:self]; 
    [_conn startAsynchronous]; 

我發現每當 - (空)要求:(ASIHTTPRequest *)要求didReceiveData:(NSData的*)數據:被稱爲緩存不會保存。任何想法?

回答

0

我用過同樣的東西。唯一的區別是,我不得不設置以下選擇:

[_conn setDidFailSelector:@selector(downloadDidFail:)]; 
[_conn setDidFinishSelector:@selector(downloadDidFinish:)]; 
[_conn setDidStartSelector:@selector(downloadDidStart:)]; 

並沒有實現任何的指定爲ASIHTTPRequestDelegate協議可選其他委託方法。現在下載完美,並在需要時調用設置選擇器。

+0

但我需要跟蹤按字節下載的進度,所以我需要從委託請求didReceiveData:[數據長度]。 – Lunayo

+0

如果您知道總大小(您可以),則可以附加自定義進度委託來接收進度並計算所下載的字節數。 – Jake

+0

是的,它的工作。我使用了自定義進度委託。非常感謝! – Lunayo