3

I had an application in which i am calling synchronised requests using session managers, in

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

i am using a global

@property(strong,nonatomic)AFHTTPSessionManager *manager;

and allocating in viewdidload like

manager = [[AFHTTPSessionManager alloc] init];
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    manager.responseSerializer.acceptableContentTypes =  [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
    AFJSONResponseSerializer *responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];

    [manager setResponseSerializer:responseSerializer];

and a group of requests are happening in a cycle. there is an option for me to cancel all requests for me where i am doing

for (manager in self.arrayOfTasks) {

        [manager invalidateSessionCancelingTasks:YES];
    }




    manager=nil;

,but the issue is after cancelling also this requests are happening again and again.it is not cancelling.can anybody guide me to find where i am going wrong?

hacker
  • 8,919
  • 12
  • 62
  • 108

1 Answers1

5

You can try this below code to cancel all the task started for AFHTTPSession Manager:

 for (NSURLSessionTask *task in manager.tasks)
    {
        [task cancel];
    }

Also for individual upload and download task cancellation:

Download task cancellation:

 for (NSURLSessionTask *task in manager.downloadTasks)
        {
            [task cancel];
        }

Upload task cancellation:

 for (NSURLSessionTask *task in manager.uploadTasks)
        {
            [task cancel];
        }