开发者

Cancelling one (or several) certain ASIHTTPRequests in an ASINetworkQueue

开发者 https://www.devze.com 2023-02-07 06:45 出处:网络
In my iPhone/iPad app I\'m handling all network and web-API-requests through a \"APIManager\" (singleton, created in AppDelegate).

In my iPhone/iPad app I'm handling all network and web-API-requests through a "APIManager" (singleton, created in AppDelegate).

Currently the APIManager contains only one single ASINetworkQueue, to which APIRequests (subclass of ASIHTTPRequest) are added and executed. In the userInfo of each APIRequest some additional information to handle the request is added (l开发者_开发知识库ike whether the response should be parsed into Core Data - and if so, which entity - or not).

When the user moves from one view (ViewA) to another (ViewX), I would like to have the possibility to cancel all the requests that ViewA have asked the APIManager to perform, while letting others continue.

Is there some functionality to find a certain request in a ASINetworkQueue (or NSOperationQueue) and send a cancellation message to it? Maybe using parameters added to the userInfo of the request?

Thanks in advance!


[queue operations] will return an NSArray of items in the queue, which you can then iterate and call 'cancel' on any you like.

Something like:

for (ASIHTTPRequest *req in [queue operations])
{
    if (shouldCancel(req))
        [req cancel];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消