ios – AFNetworking 2:取消批量请求

ios – AFNetworking 2:取消批量请求,第1张

概述我正在使用AFNetworking2代码进行批处理请求.我有副本&从示例代码粘贴并更改了上载 *** 作以进行下载.我需要取消控制器上的下载 *** 作消失.我正在尝试取消: [[self.imagesQueue.operations filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSD 我正在使用AFNetworking2代码进行批处理请求.我有副本&从示例代码粘贴并更改了上载 *** 作以进行下载.我需要取消控制器上的下载 *** 作消失.我正在尝试取消:

[[self.imagesQueue.operations filteredArrayUsingPredicate:[nspredicate predicateWithBlock:^BOol(ID evaluatedobject,NSDictionary *bindings) { return [evaluatedobject isKindOfClass:[AFhttpRequestoperation class]]; }]] makeObjectsPerformSelector:@selector(cancel)];

批量请求(下载图像):

-(voID) startDownloadImages {    NSMutableArray *mutableOperations = [NSMutableArray array];    //self.downloadOperations = [NSMutableArray array];    for (Nsstring *str in _project.frames) {        NSURLRequest *request =        [[AFhttpRequestSerializer serializer] requestWithMethod:@"GET"                                                      URLString:str                                                     parameters:nil];        AFhttpRequestoperation *operation = [[AFhttpRequestoperation alloc] initWithRequest:request];        [operation setCompletionBlockWithSuccess:^(AFhttpRequestoperation *operation,ID responSEObject) {         NSLog(@"OK %@",str);        } failure:^(AFhttpRequestoperation *operation,NSError *error) {            NSLog(@"FAILS %@",str);        }];        [mutableOperations addobject:operation];    }    NSArray *operations =    [AFURLConnectionoperation batchOfRequestoperations:mutableOperations                                         progressBlock:^(NSUInteger numberOfFinishedOperations,NSUInteger totalNumberOfOperations) {        NSLog(@"%lu of %lu complete",(unsigned long)numberOfFinishedOperations,(unsigned long)totalNumberOfOperations);    } completionBlock:^(NSArray *operations) {        NSLog(@"All operations in batch complete");    }];    self.imagesQueue = [[NSOperationQueue alloc] init];    self.imagesQueue.name = @"com.imagesqueue";    self.imagesQueue.maxConcurrentoperationCount = 1;    [self.imagesQueue addOperations:operations waitUntilFinished:NO];    //[[NSOperationQueue mainQueue] addOperations:operations waitUntilFinished:NO];}

一系列启动和取消导致EXC_BREAKPOINT(代码= EXC_ARM_BREAKPOINT,子代码= 0xdefe):

libdispatch.dylib`dispatch_group_leave:    0x37e1e7d8:  dmb    ishst    0x37e1e7dc:  ldrex  r1,[r0,#40]    0x37e1e7e0:  adds   r1,#1    0x37e1e7e2:  strex  r2,r1,#40]    0x37e1e7e6:  cmp    r2,#0    0x37e1e7e8:  bne    0x37e1e7dc                ; dispatch_group_leave + 4    0x37e1e7ea:  cmp.w  r1,#4294967295    0x37e1e7ee:  ble    0x37e1e7fe                ; dispatch_group_leave + 38    0x37e1e7f0:  mvn    r2,#2147483648    0x37e1e7f4:  cmp    r1,r2    0x37e1e7f6:  it     eq    0x37e1e7f8:  beq.w  0x37e21df8                ; _dispatch_group_wake    0x37e1e7fc:  bx     lr    0x37e1e7fe:  trap       0x37e1e800:  nop        0x37e1e802:  nop

有小费吗?

解决方法 尝试将str声明为块变量(您在块中访问它):

__block Nsstring *str;for (str in _project.frames) {

您还可以在执行取消选择器之前尝试检查 *** 作是否已完成.

在视图中将消失方法,您可以调用映像队列上的cancelAllOperations来取消所有剩余的 *** 作.

总结

以上是内存溢出为你收集整理的ios – AFNetworking 2:取消批量请求全部内容,希望文章能够帮你解决ios – AFNetworking 2:取消批量请求所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1022154.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存