使用自定义会话配置创建 AFHTTPSessionManager 的单调子类的正确方法是什么?
class DefaultSessionConfiguration: NSURLSessionConfiguration {
override init () {
super.init()
self.HTTPShouldSetCookies = true
HTTPCookieStorage?.cookieAcceptPolicy = NSHTTPCookieAcceptPolicy.Always
HTTPAdditionalHeaders = [ "Content-Type": "application/json"];
}
}
let baseUrl = "https://google.com"
class HTTPManager: AFHTTPSessionManager {
static let _sharedAPIManager = HTTPManager(baseURL: NSURL(string: baseUrl)!, sessionConfiguration:DefaultSessionConfiguration())
class var sharedInstance : HTTPManager {
return _sharedAPIManager
}
override init(baseURL url: NSURL!, sessionConfiguration session:NSURLSessionConfiguration? ) {
super.init(baseURL: url, sessionConfiguration: session)
self.responseSerializer = AFJSONResponseSerializer() as AFJSONResponseSerializer
self.requestSerializer = AFJSONRequestSerializer() as AFJSONRequestSerializer
}
}
在尝试使用此代码时,因为 self.sessionManager = HTTPManager.sharedInstance
它总是因消息而崩溃
[MyApp.DefaultSessionConfiguration setHTTPShouldSetCookies:]:无法识别的选择器发送到实例 0x7f99f8f31b70
但是 MyApp.DefaultSessionConfiguration 是 NSURLSessionConfiguration 的子类,并且肯定有这个方法。
那么,我们如何解决这个问题呢?