AFNetworking 2.0 cancel specific task

前端 未结 3 683
伪装坚强ぢ
伪装坚强ぢ 2021-02-01 21:45

I am trying out afnetworking 2.0 and just trying to figure out how to cancel specific tasks. The old way would be to use something like

[self cancelAllHTTPOperat         


        
3条回答
  •  我在风中等你
    2021-02-01 21:54

    you can do the following

    NSArray *operations = [[[MyClient sharedClient] operationQueue] operations];
    if(operations && operations.count > 0){
        for (NSOperation *operation in operations) {
            if([operation isKindOfClass:[AFHTTPRequestOperation class]]){
                AFHTTPRequestOperation *httpOperation = (AFHTTPRequestOperation *)operation;
                NSLog(@"%@", [[httpOperation request] URL]);
                //--- if this is your request then cancel it --> [httpOperation cancel];
            }
        }
    }
    

    Where MyClient is a child of AFHTTPClient and the function sharedClient is a static function which returns a singleton instance of MyClient

提交回复
热议问题