diff --git a/Cartfile.resolved b/Cartfile.resolved index 6a0d62c..159e604 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,3 +1,3 @@ -github "Quick/Nimble" "v7.3.1" -github "Quick/Quick" "v1.3.2" +github "Quick/Nimble" "v8.0.1" +github "Quick/Quick" "v2.1.0" github "vadymmarkov/When" "4.0.0" diff --git a/Sources/Networking.swift b/Sources/Networking.swift index 69547da..c4c0dd7 100644 --- a/Sources/Networking.swift +++ b/Sources/Networking.swift @@ -34,24 +34,15 @@ public final class Networking: NSObject, URLSessionDelega promise.resolve(Void()) } - let sessionConfiguration: SessionConfiguration let mockProvider: MockProvider? let queue: OperationQueue + let session: URLSession + var customHeaders = [String: String]() var requestStorage = RequestStorage() var mode: NetworkingMode = .async - weak var sessionDelegate: URLSessionDelegate? - - lazy var session: URLSession = { [unowned self] in - let session = URLSession( - configuration: self.sessionConfiguration.value, - delegate: self.sessionDelegate ?? self, - delegateQueue: nil) - return session - }() - var requestHeaders: [String: String] { var headers = customHeaders headers["Accept-Language"] = Header.acceptLanguage @@ -68,16 +59,24 @@ public final class Networking: NSObject, URLSessionDelega public init(mode: NetworkingMode = .async, mockProvider: MockProvider? = nil, - sessionConfiguration: SessionConfiguration = SessionConfiguration.default, - sessionDelegate: URLSessionDelegate? = nil) { + session: URLSession) { self.mockProvider = mockProvider - self.sessionConfiguration = sessionConfiguration - self.sessionDelegate = sessionDelegate queue = OperationQueue() + self.session = session super.init() reset(mode: mode) } + public init(mode: NetworkingMode = .async, + mockProvider: MockProvider? = nil, + configuration: SessionConfiguration = .default) { + self.mockProvider = mockProvider + queue = OperationQueue() + self.session = URLSession(configuration: configuration.value) + super.init() + reset(mode: mode) + } + public func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { var disposition: URLSession.AuthChallengeDisposition = .performDefaultHandling var credential: URLCredential? diff --git a/Sources/Request/RequestStorage.swift b/Sources/Request/RequestStorage.swift index 5201eef..3497364 100644 --- a/Sources/Request/RequestStorage.swift +++ b/Sources/Request/RequestStorage.swift @@ -25,9 +25,13 @@ final class RequestStorage { } func saveAll() { - let data = NSKeyedArchiver.archivedData(withRootObject: requests) - userDefaults.set(data, forKey: key) - userDefaults.synchronize() + if #available(OSX 10.11, *) { + let data = NSKeyedArchiver.archivedData(withRootObject: requests) + userDefaults.set(data, forKey: key) + userDefaults.synchronize() + } else { + // Fallback on earlier versions + } } // MARK: - Remove