Created
January 30, 2020 15:14
-
-
Save SergLam/1993d2f3b303286de13c2eaaf0417070 to your computer and use it in GitHub Desktop.
Alamofire - custom session manager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Alamofire | |
import Foundation | |
final class CustomAlamofireManager: Alamofire.SessionManager { | |
private static let requestTimeOutTimeInterval: TimeInterval = { | |
#if DEBUG | |
return 30.0 | |
#else | |
return 120.0 | |
#endif | |
}() | |
static let sharedManager: CustomAlamofireManager = { | |
// NOTE: Background configuration is required to handle | |
// network requests correctly while app come foreground / background | |
let configuration = URLSessionConfiguration.background(withIdentifier: "com.bundle_id") | |
configuration.httpAdditionalHeaders = Alamofire.SessionManager.defaultHTTPHeaders | |
configuration.timeoutIntervalForRequest = requestTimeOutTimeInterval | |
configuration.timeoutIntervalForResource = requestTimeOutTimeInterval | |
configuration.requestCachePolicy = .useProtocolCachePolicy | |
return CustomAlamofireManager(configuration: configuration) | |
}() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment