AFNetworking并设置请求队列

时间:2013-04-26 20:49:40

标签: ios objective-c afnetworking

我正在进行AFRequestionOperation调用:

- (id)init {
    if (self = [super init]) {
        // Other code

        AFHTTPClient *client = [[AFHTTPClient alloc] init];
        [client registerHTTPOperationClass:[AFImageRequestOperation class]];
        [client.operationQueue setMaxConcurrentOperationCount:2];

        self.HTTPClient = client;
    }

    return self;
}

当我需要提出请求时:

AFHTTPRequestOperation *request = [self.HTTPClient HTTPRequestOperationWithRequest:urlRequest success:^(AFHTTPRequestOperation *operation, id responseObject) {
    // Code
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    // Code
}];

[self.HTTPClient enqueueHTTPRequestOperation:request];

当我检查队列时:

DLog(@"queue: %@", self.HTTPClient.operationQueue);

它将队列显示为null

它不会打电话。

我可以使用:

[request start];

但很确定不使用队列。

1 个答案:

答案 0 :(得分:1)

您需要使用指定的初始值设定项AFHTTPClient

- (id)initWithBaseURL:(NSURL *)url;