gpt4 book ai didi

ios - 当设备因错误而锁定时,URLSessionConfiguration 后台下载任务失败 - 与后台传输服务的连接丢失

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

我得到一个

Error Domain=NSURLErrorDomain Code=-997 "Lost connection to background transfer service"

当我在启动后台下载过程后锁定屏幕时。我正在使用 Alamofire,但我认为这也会发生在常规 URLSession 上。如果我软关闭应用程序,下载会继续工作,但一旦我锁定我的设备,它就会开始抛出此错误。

下面是代码的相关部分:

private(set) lazy var alamoSessionManager: SessionManager = {
let config = URLSessionConfiguration.background(withIdentifier: "MySession")
config.isDiscretionary = true
config.sessionSendsLaunchEvents = true
config.shouldUseExtendedBackgroundIdleMode = true
return Alamofire.SessionManager(configuration: config)
}()

let route = buildRouter()

alamoSessionManager.request(url, method: route.method, parameters: route.parameters, encoding: JSONEncoding.default, headers: route.headers)

我查看了控制台以查看是否有任何守护进程崩溃但找不到任何守护进程。锁定屏幕后我立即看到三个错误:

BKLogEvent: couldn't find CombinedSequence properties

Task <>.<48> finished with error - code: -999

Task <>.<48> load failed with error Error Domain=NSURLErrorDomain Code=-997 "Lost connection to background transfer service" UserInfo={NSErrorFailingURLStringKey=, NSErrorFailingURLKey=, _NSURLErrorRelatedURLSessionTaskErrorKey=, _NSURLErrorFailingURLSessionTaskErrorKey=, NSLocalizedDescription=Lost connection to background transfer service} [-997]

error._userInfo 是这样的:

▿ Optional<AnyObject>
▿ some : 5 elements
▿ 0 : 2 elements
- key : NSErrorFailingURLStringKey
- value : https://www.myweb.com/api
▿ 1 : 2 elements
- key : NSErrorFailingURLKey
- value : https://www.myweb.com/api
▿ 2 : 2 elements
- key : _NSURLErrorRelatedURLSessionTaskErrorKey
▿ value : 2 elements
- 0 : BackgroundDataTask <C39E-2FC73>.<27>
- 1 : LocalDataTask <C39E-2FC73>.<27>
▿ 3 : 2 elements
- key : _NSURLErrorFailingURLSessionTaskErrorKey
- value : BackgroundDataTask <C39E-2FC73>.<27>
▿ 4 : 2 elements
- key : NSLocalizedDescription
- value : Lost connection to background transfer service

最佳答案

Alamofire 目前与后台 session 并不真正兼容,这既是因为无法持久化和重新连接其闭包 API,也是因为它 invalidateAndCancel() URLSessiondeinitd 时。我们建议您直接将 URLSession 用于后台 session ,或将前台 session 与后台任务 API 结合使用。

关于ios - 当设备因错误而锁定时,URLSessionConfiguration 后台下载任务失败 - 与后台传输服务的连接丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54975122/

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