从NSOperationQueue取消ASIHTTPRequest

时间:2013-02-02 08:47:55

标签: ios objective-c asihttprequest nsoperationqueue

我的问题是每当我尝试取消ASIHTTPRequest中添加的NSOperationQueue时,没有任何事情它会调用代理并且不停止,我使用以下代码:

[request cancel];

[request clearDelegatesAndCancel];

但似乎没有用。

我的代码:

[operationQueue addOperationWithBlock:^{

    AsyncCallerClass *asyncClass=[[AsyncCallerClass alloc] init];
    DataSet *ds=[[DataSet alloc]init];
    asyncClass.MethodParameters=[[NSMutableDictionary alloc]init];
    asyncClass.req=cusRequest;
    asyncClass.mehtodName=@"testMethod";
    asyncClass.xmlNameSpace=@"http://test.org/";
    asyncClass.xmlURLAddress=@"http://myPC/service.asmx";
    NSMutableData *data;
    data=[asyncClass getDataFromWebService];
    [ds parseXMLWithData:data];

    NSMutableDictionary *Data_Dictionary=[[NSMutableDictionary alloc]initWithDictionary:[ds getRowsForTable:@"DataTable"] ];

    currRow=[Data_Dictionary objectForKey:@"0"];

}];

现在在AsyncCallerClass类

ASIHTTPRequest *myRequest = [ASIHTTPRequest requestWithURL:url];

[myRequest setRequestMethod:@"POST"];

[myRequest addRequestHeader:@"Content-Type" value:@"text/xml; charset=utf-8"];

[myRequest addRequestHeader:@"SOAPAction" value:self.SOAPActionURL];

NSString *messageLength = [NSString stringWithFormat:@"%d",[sRequest length]];

[myRequest addRequestHeader:@"Content-Length" value:messageLength];

[myRequest appendPostData:[sRequest dataUsingEncoding:NSUTF8StringEncoding]];

[myRequest setDelegate:self];

[myRequest setTimeOutSeconds:120];

[myRequest startSynchronous];

并取消它我在AsyncCallerClass中调用一个方法

-(void) cancelMe:(NSOperationQueue*) myQueue  
{

[myRequest cancel];

[myRequest clearDelegatesAndCancel];

}

0 个答案:

没有答案