gpt4 book ai didi

ios - 带有完成 block 的 AFNetwork 2.0 队列?

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

我如何在 AFNetwork 2.0 上创建队列并为添加的操作完成时设置完成处理程序?

目前我有这个

ASINetworkQueue *queue = [[ASINetworkQueue alloc] init];

[queue setDelegate:self];
[queue setQueueDidFinishSelector:@selector(refeshInterface)];

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[queue addOperation:request];

ASIFormDataRequest *request2 = [ASIFormDataRequest requestWithURL:url2];
[queue addOperation:request2];

[queue go]

但我需要将其转换为 AFNetwork。到目前为止我发现的所有解决方案似乎都使​​用 AFHTTPClient,AFNetwork 2.0 中不存在。

我是 AFNetwork 的新手,所以非常感谢一些例子。

谢谢!

最佳答案

你需要

+ (NSArray *)batchOfRequestOperations:(NSArray *)operations
progressBlock:(void (^)(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations))progressBlock
completionBlock:(void (^)(NSArray *operations))completionBlock

AFURLConnectionOperation 的方法。

请看下面的例子

NSMutableArray *operations = [NSMutableArray array];

for (DGSocialImage *socialImage in socialImages) {
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:socialImage.url];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFImageResponseSerializer new];
[operations addObject:operation];
}
NSArray *batchOperations = [AFURLConnectionOperation batchOfRequestOperations:operations
progressBlock:NULL
completionBlock:^(NSArray *operations) {
NSError *error;
for (AFHTTPRequestOperation *op in operations) {
if (op.isCancelled){
return ;
}
if (op.responseObject){
// process your responce here
}
if (op.error){
error = op.error;
}
}
}];
[[NSOperationQueue mainQueue] addOperations:batchOperations waitUntilFinished:NO];

关于ios - 带有完成 block 的 AFNetwork 2.0 队列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22582860/

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