0

我对 AFNetworking 比较陌生,希望为以下问题找到更好的解决方案。

我在我的 iOS 应用程序开始时使用了 2 个 AFJSONRequestOperations。

AFJSONRequestOperation *operation1 = [AFJSONRequestOperation JSONRequestOperationWithRequest:request1 success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
    // do something
}failure:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON, NSError *error){
    // do something
}];

AFJSONRequestOperation *operation2 = [AFJSONRequestOperation JSONRequestOperationWithRequest:request2 success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
    // do something
}failure:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON, NSError *error) {
    // do something
}];

[operation1 start];
[operation2 start];

我等待两个操作完成并开始进一步处理。

我想我可以将这两个操作结合到enqueueBatchOfHTTPRequestOperationsWithRequests方法中。

AFHTTPClient *client = [[AFHTTPClient alloc] init];

NSArray *requests = [NSArray arrayWithObjects:operation1, operation2, nil];

[client enqueueBatchOfHTTPRequestOperationsWithRequests:requests progressBlock:^(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations) {
    // track operations
}completionBlock:^(NSArray *operations) {
    // do something
}];

所以我想跟踪完成的操作并分别为每个操作执行完成块。我可以用 AFHTTPClient 执行吗?

4

0 回答 0