本文介绍了在Alamofire中更改timeoutIntervalForRequest的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用
let manager = Alamofire.SessionManager.default
manager.session.configuration.timeoutIntervalForRequest = 3
manager.request(url).response {}
但似乎没有用,有什么建议吗?
but seems not worked, Any suggestion?
推荐答案
这对我有用:)
let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = TimeInterval(7)
configuration.timeoutIntervalForResource = TimeInterval(7)
let session = URLSession(configuration: configuration)
let task = session.dataTask(with: url) {}
根据Apple的文档,对已初始化的URLSession配置的更改无效。如果您想要自定义超时,请在请求中设置值,或者使用自定义配置创建自定义URLSession,如
Changes to the configuration of an already initialized URLSession have no effect, per Apple's documentation. If you want a custom timeout, either set the value on your requests, or create a custom URLSession with a custom configuration, as outlined in document
这篇关于在Alamofire中更改timeoutIntervalForRequest的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!