[英]Alamofire request is being cancelled
Background 背景
I am creating a series of requests to grab a chunk of a file. 我正在创建一系列请求以获取文件的一部分。 The chunk size stays the same so the number of requests may change depending on which file I am downloading.
块大小保持不变,因此请求数可能会根据我下载的文件而改变。 For smaller files, and thus smaller number of requests I seem to reliably succeed.
对于较小的文件,因此对于较小数量的请求,我似乎可以可靠地成功。 However once my request chain reaches the 10+ ballpark I start to get an error.
但是,一旦我的请求链达到10多个标准,我就会开始出错。
Error 错误
I am getting an error from what appears to be Alamofire. 我从似乎是Alamofire的错误中获取了错误。
Error code -999 cancelled.
Looking at other purposed solutions 寻找其他有针对性的解决方案
From the searching I have done it seems that this occurs when either the session manager is deallocated
or another request was kicked off before I received a response from the previous request
. 从搜索完成后,似乎出现这种情况,是
another request was kicked off before I received a response from the previous request
the session manager is deallocated
或another request was kicked off before I received a response from the previous request
。
I made my session manager static, as stated by some other posts to handle the deallocating issue, but I still get this error. 如其他一些文章所述,我将会话管理器设为静态,以处理分配问题,但仍然出现此错误。
I don't think the next request is being called before the first finishes as my logs seem to be printing out in order and the failure is rather random. 我认为在第一个请求完成之前不会调用下一个请求,因为我的日志似乎按顺序打印出来,并且失败是随机的。 I would expect that the requests would overwrite quite reliably.
我希望这些请求将非常可靠地覆盖。
Is there any thing else that causes this error code to occur? 还有其他事情导致此错误代码发生吗?
Additional Logs 其他日志
NetworkFilesClient.swift:351 - Error downloading chunk URL: MY_URL_HERE,
Range: bytes=29360128-33554432,
Error: Error Domain=NSURLErrorDomain Code=-999 "cancelled"
UserInfo={NSErrorFailingURLKey=MY_URL_HERE,
NSLocalizedDescription=cancelled,
NSErrorFailingURLStringKey=MY_URL_HERE}
What works for me: 什么对我有用:
sessionManager.session.finishTasksAndInvalidate()
I put this at the end of my response handling. 我将此放在响应处理的末尾。 Why?
为什么? No clue...
没有线索...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.