如何使用ASIHTTPRequest(ASYNC)跟踪下载进度

|| 我目前在网站上使用异步调用我的API(我设置)。我正在将ASIHTTPRequest的setDownloadProgressDelegate与UIProgressView一起使用。但是我不知道如何调用选择器(updateProgress),该选择器会将CGFloat \'progress \'设置为progressView \的进度。我尝试了以下方法,但是两个进度均为零。请您告诉我如何进行这项工作?
(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
会更改进度指示器本身。     
        对于仍在寻找此答案的人们:请注意,不建议使用ASI,而应改用NSURLSession或ASIHTTPRequest。 实现您想要的一种方法是将ѭ4设置为您自己的类并实现
setProgress:
。在此实现中,更新您的进度变量,然后调用
[progressView setProgress:];
或在代码中,设置请求的下载进度委托:
[request setDownloadProgressDelegate:self];
然后将方法添加到您的类中:
- (void)setProgress:(float)progress
{
    currentProgress = progress;
    [progressView setProgress:progress];
}
    
        顺便说一句:下载内容时,NS * Connection似乎比ASI *快很多。 无论如何,此页面上的示例都意味着您不需要手动将值从下载对象“复制”到进度视图对象。 实际上,基于计时器的代码正在从进度视图中获取进度,该视图应该已经显示了进度。如果我正确理解ASIHTTP *,那么在此代码中根本就不需要计时器。     

要回复问题请先登录注册