1

我有一个使用 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

    }];

我检查successandfailure回调是否在主线程中。
如何使这些回调不像回调那样在主线程中运行progress

4

1 回答 1

2

您可以设置operationQueue以选择如何调用委托方法以及completionQueue选择如何调用完成块。

于 2016-03-25T09:11:28.210 回答