[英]Why can't I init Alamofire 4 session manager?
I'm having issues initalizing an Alamofire 4.0 session manager. 我在启动Alamofire 4.0会话管理器时遇到问题。 My code as below: 我的代码如下:
func configAlamoManager() {
let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForRequest = 20
if Features.JWT_AUTH {
let user = SessionManager.getCurrentUser()
if let jwtToken = user.jwtToken {
let bearer = "Bearer \(jwtToken)"
configuration.httpAdditionalHeaders = ["MyCompany-Authorization": bearer, "MyCompany-User-Agent": Config.MyCompanyUserAgentDataString]
} else {
configuration.httpAdditionalHeaders = ["MyCompany-User-Agent": Config.MyCompanyUserAgentDataString]
}
}
alamoManager = Alamofire.SessionManager(configuration: configuration)
}
For the line alamoManager = Alamofire.SessionManager(configuration: configuration)
I am getting the error "Cannot invoke SessionManager with an argument list of type (configuration: URLSessionConfiguration)". 对于一行alamoManager = Alamofire.SessionManager(configuration: configuration)
我收到错误消息“无法使用类型(配置:URLSessionConfiguration)的参数列表调用SessionManager”。 What is the issue here? 这是什么问题? I am following the docs: https://github.com/Alamofire/Alamofire#modifying-the-session-configuration
. 我正在关注文档: https://github.com/Alamofire/Alamofire#modifying-the-session-configuration
: https://github.com/Alamofire/Alamofire#modifying-the-session-configuration
。 I seem to be initializing the session manager in exactly the same way. 我似乎正在以完全相同的方式初始化会话管理器。 Any pointers on this would be really appreciated! 任何对此的指针将不胜感激!
Probably you have this line : 大概你有这行:
var alamoManager = Alamofire.SessionManager
but with this line you invoke the common Alamofire.SessionManager
initialization. 但是通过这一行,您可以调用常见的Alamofire.SessionManager
初始化。
Try to declare your global property as: 尝试将您的全局属性声明为:
var alamoManager = SessionManager()
so it become a generic SessionManager
type with the default SessionManager
initialization. 因此它成为具有默认SessionManager
初始化的通用SessionManager
类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.