ASIHttpRequest 請求:didReceiveBytes:未按預期工作 (ASIHttpRequest request:didReceiveBytes: not working as expected)


問題描述

ASIHttpRequest 請求:didReceiveBytes:未按預期工作 (ASIHttpRequest request:didReceiveBytes: not working as expected)

I'm sure there's a very easy explanation to this, but I'm tearing my hair out over the matter.

    ‑(void)addRequestWithUrl:(NSURL *)url savePath:(NSString *)path
    {
      ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
      request.userInfo = [[NSMutableDictionary alloc] initWithObjectsAndKeys:path, @"savePath", nil];
      networkQueue.showAccurateProgress = YES;
      [self.networkQueue addOperation:request];
      [self.networkQueue setDownloadProgressDelegate:self];
    }

    ‑(void)request:(ASIHTTPRequest *)request didReceiveBytes:(long long)bytes
    {
       DLog(@"bytes: %llu", bytes);
    }

didReceiveBytes is not ever called. If I set the download progress delegate to each request instead of the queue the didReceiveBytes method is called, but only after each request is completely finished, and always with a value of 1.

Any suggestions what's wrong here? (working on iOS btw)

‑‑‑‑‑

參考解法

方法 1:

It may help:

[request setDidReceiveDataSelector:@selector(request:didReceiveBytes:)]; 

方法 2:

Yeah it took me a while to figure this one out, I got the same result until I started to look into the ASIHTTPRequest code. All you have to do is add:

request.showAccurateProgress = YES;

before you networkQueue.showAccurateProgress = YES; because otherwise it does not read the individual head info of each file and add up the bytes.

(by cboemohsinjh1vpdata)

參考文件

  1. ASIHttpRequest request:didReceiveBytes: not working as expected (CC BY‑SA 3.0/4.0)

#asihttprequest #iOS






相關問題

遠程服務器上的請求總是失敗 (Request always fail on distant server)

ASIHTTPRequest 緩存我的數據。我不想要任何類型的緩存 (ASIHTTPRequest caches my data. I don't want any kind of cache)

在調用之前釋放了 didFinishSelector ASIHTTPRequest 的自定義委託類 (Custom delegate class for didFinishSelector ASIHTTPRequest being deallocated before called)

Android:在後台上傳/下載文件數量的最佳方式 (Android: best way to upload/download number of files in background)

Ghi giá trị bài đăng trong ASIFormDataRequest (Log Post Value in ASIFormDataRequest)

ASIHTTPRequest - 下載問題 (ASIHTTPRequest - download problem)

ASIHTTPRequest 離線模式連接失敗 (ASIHTTPRequest offline mode connection failure)

ASIHttpRequest 請求:didReceiveBytes:未按預期工作 (ASIHttpRequest request:didReceiveBytes: not working as expected)

如何讓 Ruby on Rails 與 ASIHTTPRequest 一起使用? (How do I get Ruby on Rails to work with ASIHTTPRequest?)

可以指定一個 NSObject 作為多個 ASIHTTPRequests 的代表嗎? (OK to assign one NSObject as the delegate of multiple ASIHTTPRequests?)

需要幫助將 NSXMLParser 與 ASIHTTPRequest 一起使用 (need help using NSXMLParser with ASIHTTPRequest)

處理 ASIHTTPRequest 多個請求 (Handling ASIHTTPRequest Multiple Requests)







留言討論