Looking over the documentation of NSURLSession and NSURLSessionConfiguration, I was under the impression I should configure it with a dictionary li
Swift 3 extension
extension URLSession {
func withProxy(proxyURL: String, proxyPort: Int) -> URLSession {
var configuration = self.configuration
configuration.connectionProxyDictionary = [
kCFNetworkProxiesHTTPEnable as AnyHashable : true,
kCFNetworkProxiesHTTPPort as AnyHashable : proxyPort,
kCFNetworkProxiesHTTPProxy as AnyHashable : proxyURL
]
return URLSession(configuration: configuration, delegate: self.delegate, delegateQueue: self.delegateQueue)
}
}
Usage:
let session = URLSession().withProxy(proxyURL: "xxxxxx", proxyPort: 8321)