如何使用ASIHTTPRequest(ASYNC)跟踪下载进度 [英] How to track the progress of a download using ASIHTTPRequest (ASYNC)
问题描述
我目前正在我的网站上使用异步调用我的API(我设置)。我正在使用ASIHTTPRequest的setDownloadProgressDelegate和UIProgressView。但是我不知道如何调用一个选择器(updateProgress),它将把一个CGFloat'progress'设置为progressView的进度。我尝试了以下,但两个进展都是零。请告诉我如何才能使这个工作?
I am currently using an asynchronous call to my API (I setup) on my site. I am using ASIHTTPRequest's setDownloadProgressDelegate with a UIProgressView. However I don't know how I can call a selector (updateProgress) which will set a CGFloat 'progress' to the progressView's progress. I tried the following, but both the progresses were zero. Please can you tell me how I can get this working?
(in some method)
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:[url stringByAppendingFormat:@"confidential"]]];
[request setDownloadProgressDelegate:progressView];
[NSTimer scheduledTimerWithTimeInterval:1.0f/60.0f target:self selector:@selector(updateProgress:) userInfo:nil repeats:YES];
[request setCompletionBlock:^{~100 lines of code}];
[request setFailedBlock:^{~2 lines of code :) }];
[request startAsynchronous];
- (void) updateProgress:(NSTimer *)timer {
if (progressView.progress < 1.0) {
currentProgress = progressView.progress;
NSLog(@"currProg: %f --- progressViewProg: %f", currentProgress, progressView.progress);
}
else {
[timer invalidate];
}
return;
}
推荐答案
尝试添加到您的请求:
[request setShowAccurateProgress:YES];
无法帮助您拨打 updateProgress
, ASIHTTPRequest
将改变进度指示器本身。
It won't help you to call updateProgress
, ASIHTTPRequest
will change progress indicator itself.
这篇关于如何使用ASIHTTPRequest(ASYNC)跟踪下载进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!