gpt4 book ai didi

ios - AFNetworking enqueRequestOperations 在调用所有 AFJSONRequestOperation 完成之前触发完成

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:43:34 26 4
gpt4 key购买 nike

AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://twitter.com"]];

NSURL *url = [NSURL URLWithString:@"https://alpha-api.app.net/stream/0/posts/stream/global"];
NSURLRequest *r = [NSURLRequest requestWithURL:url];

AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:r success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"App.net Global Stream: %@", JSON);
} failure:nil];
AFJSONRequestOperation *operation1 = [AFJSONRequestOperation JSONRequestOperationWithRequest:r success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"App.net Global Stream: %@", JSON);
} failure:nil];

[client enqueueBatchOfHTTPRequestOperations:@[operation, operation1] progressBlock:^(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations) {

} completionBlock:^(NSArray *operations) {
NSLog(@"%@", operations);
}];

enqueueBatchOfHTTPRequestOperations 完成在操作和操作 1 block 之前触发。

读过 https://github.com/AFNetworking/AFNetworking/issues/362并尝试使用 dispatch_group 进行可能的修复,但它仍然不起作用。

最佳答案

更改您的代码以使用 AFHTTPRequestOperation 而不是 AFJSONRequestOperation 并使用 NSJSONSerialization 手动解析 JSON,您会发现您的队列完成 block 会在所有操作按要求完成后触发。

关于ios - AFNetworking enqueRequestOperations 在调用所有 AFJSONRequestOperation 完成之前触发完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16086051/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com