問題描述
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.