gpt4 book ai didi

iphone - ASIHTTPRequest 请求取消

转载 作者:太空狗 更新时间:2023-10-30 03:56:45 25 4
gpt4 key购买 nike

我一直在使用 ASIHTTPRequest 来获取数据,我想取消请求我该怎么做??我像这样编写代码..

-(void) serachData{
NSURL *url= [NSURL URLWithString:self.safestring];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setTimeOutSeconds:7200];
[request setDelegate:self];
[request startAsynchronous];
}

- (NSMutableDictionary *)requestFinished:(ASIHTTPRequest *)request
{
NSLog(@"requestFinished");
NSString *responseString = [request responseString];
SBJsonParser *json = [[SBJsonParser alloc] init];
NSMutableArray *array = [[NSMutableArray alloc] initWithObjects[jsonobjectWithString:responseString], nil];
NSLog(@"array %@",array);
}

- (void)requestFailed:(ASIHTTPRequest *)request{
NSLog(@"requestFailed");
}

//如果我按下取消按钮(当 requestFinished/requestFailed 方法正在处理中)然后 ASIHTTPRequest 失败并完成方法停止/中止!我该怎么做??

 -(IBAction)CancleREquest:(id)sender{
NSLog(@"CancleREquest");
}

最佳答案

您的取消特定的 ASIHTTPRequest 然后:

if(![yourASIHTTPRequest isCancelled]) 
{
// Cancels an asynchronous request
[yourASIHTTPRequest cancel];
// Cancels an asynchronous request, clearing all delegates and blocks first
[yourASIHTTPRequest clearDelegatesAndCancel];
}

注意:要取消所有ASIHTTPRequest则:

for (ASIHTTPRequest *request in ASIHTTPRequest.sharedQueue.operations)
{
if(![request isCancelled])
{
[request cancel];
[request setDelegate:nil];
}
}

编辑:使用AFNetworking因为 ASIHTTPRequest 已被弃用,因为它自 2011 年 3 月以来一直没有更新。

关于iphone - ASIHTTPRequest 请求取消,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10780696/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com