質問

I have successfully implemented the ASIHTTPRequest framework to download a file from a URL and it saves in my Document Directory - YIPPIE!!!

Now I would like to show a Progress of some sort, so that the user can what is going on.

With the UIWebViewDelegate there are the following methods - I was hoping to use something similar.

-(void)webViewDidStartLoad:(UIWebView *)webView


-(void)webViewDidFinishLoad:(UIWebView *)webView

Is there something similar to use with ASIHTTP??

役に立ちましたか?

解決

Here is an example mixing MBProgressHUD and ASI.

The idea is you start your updating before the begin the request and you end the updating in either the completion or failed blocks.

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.labelText = @"Updating…";

NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setCompletionBlock:^{
   [MBProgressHUD hideHUDForView:self.view animated:YES];

   // Use when fetching text data
   NSString *responseString = [request responseString];

   // Use when fetching binary data
   NSData *responseData = [request responseData];
}];
[request setFailedBlock:^{
   [MBProgressHUD hideHUDForView:self.view animated:YES];
   NSError *error = [request error];
}];
[request startAsynchronous];
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top