gpt4 book ai didi

ios - 连接无限循环 :didReceiveData in AFURLConnectionOperation. m

转载 作者:行者123 更新时间:2023-11-29 01:49:08 25 4
gpt4 key购买 nike

我正在将 AFNetworking2 用于我的 iOS 项目,该项目需要大量图像加载。

下载一定数量的图片后,所有发出的请求都会在操作队列中排队,永远不会出去。

我发现那是因为在

AFURLConnectionOperation.m,(void)connection:didReceiveData

有一个 while(YES) 循环,只有在

时才会中断

[self.outputStream hasSpaceAvailable]

或者当

self.outputStream.streamError

发生。

但是,就我而言,[self.outputStream hasSpaceAvailable] 返回 NO,并且操作仍然停留在 while (YES) 循环中。

有人遇到过这个问题吗?解决方案是什么?

代码如下

AFURLConnectionOperation.m,(void)connection:didReceiveData

上下文:

- (void)connection:(NSURLConnection __unused *)connection
didReceiveData:(NSData *)data
{
NSUInteger length = [data length];
while (YES) {
...
if ([self.outputStream hasSpaceAvailable]) {
...
break;
}
if (self.outputStream.streamError) {
....
return;
}
}
...
}

注意:我目前正在使用下面的代码覆盖该函数来解决该问题。

- (void)connection:(NSURLConnection __unused *)connection
didReceiveData:(NSData *)data
{
NSUInteger length = [data length];
if ([self.outputStream hasSpaceAvailable]) {
const uint8_t *dataBuffer = (uint8_t *) [data bytes];
[self.outputStream write:&dataBuffer[0] maxLength:length];
}
}

最佳答案

这似乎是 AFNetworking 中的一个错误。见here .

有一个已提交的修复 mentioned在这个问题上,但由于某种原因(2.5.4)似乎在最新版本中不可用。

关于ios - 连接无限循环 :didReceiveData in AFURLConnectionOperation. m,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31598627/

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