我正在使用ASIHTTPRequest向Web服務器發送請求。它一切正常。但現在,當我撥打grabURLInBackground
方法時,會向給定的URL發送請求。取消ASIHTTPRequest - 初學者
但現在,我需要取消請求(如停止發送,並停止從URL中下載內容),方法如下:viewWillDissapear
。我怎樣才能做到這一點 ?幫助
- (IBAction)grabURLInBackground:(id)sender
{
NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
// Use when fetching text data
NSString *responseString = [request responseString];
// Use when fetching binary data
NSData *responseData = [request responseData];
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
NSError *error = [request error];
}
我沒有在'ASIHTTPRequest'中的'Queue'中使用我的應用程序。那麼我可以使用你的代碼嗎? – user1315906 2012-04-19 15:49:47
如果我在VIewDidDissapear或ViewDidUnload中使用它,有什麼危險?我有一個標籤欄控制器,所以當請求正在運行時,如果用戶點擊另一個欄,我需要取消請求。你認爲如果使用你的代碼解決它的理想嗎? – user1315906 2012-04-19 16:04:10
對不起,它應該是viewDidDisappear ... – 2012-04-19 16:05:51