Search code examples
objective-cafnetworking-3afhttpsessionmanager

AFHTTPSessionManager success callback are in main thread


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?


Solution

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