1

I have a request using AFHTTPSessionManager:

    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [manager.requestSerializer setAuthorizationHeaderFieldWithUsername:@"username" password:@"password"];

    [manager GET:[NSString stringWithFormat:@"%@post/%ld",C_baseURL,(long)post_id] parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {

        // this called not in main thread

    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {

        //  this called in main thread

    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

        //  this called in main thread

    }];

I check that the success and failure callback are in main thread.
How to make those callbacks not run in main thread like progress callback?

dann
  • 853
  • 5
  • 17

1 Answers1

2

You can set the operationQueue to choose how delegate methods are called and the completionQueue to choose how completion blocks are called.

Wain
  • 118,658
  • 15
  • 128
  • 151
  • Thanks @Wain, but can you give me more clue how to do this.. I was googling but still have no clue how to set `operationQueue` and `completionQueue` – dann Mar 25 '16 at 09:29
  • 1
    You want `manager.completionQueue = someDispatchQueue`, where, perhaps, `someDispatchQueue` is some queue you created for the purposes of background completion handlers. If you really wanted to set the `operationQueue` (which seem unrelated to your question), it would be `manager.operationQueue = someOperationQueue`. – Rob Mar 25 '16 at 09:39
  • Thank you Wain and @Rob, I understand now :) – dann Mar 25 '16 at 09:45