Created
June 23, 2022 10:53
-
-
Save mazharulbelal/316704ff0e0256da276f9f0cb8f55d07 to your computer and use it in GitHub Desktop.
Alamofire Cache policy setup
This file contains 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
private func apiCalling(url: String,method: HTTPMethod,parameters: [String : Any]?,header: HTTPHeaders?, cachePolicy: Bool, completion: @escaping COMPLETION_HANDLER<Data>) { | |
let configuration = URLSessionConfiguration.default | |
configuration.requestCachePolicy = . reloadIgnoringLocalAndRemoteCacheData | |
var req = URLRequest(url: URL(string: url)!) | |
req.httpMethod = method.rawValue | |
req.headers = API_HEADER | |
req.cachePolicy = cachePolicy ? .returnCacheDataDontLoad : .reloadIgnoringLocalAndRemoteCacheData | |
AF.request(req) | |
.validate(statusCode: 200..<300) | |
.responseJSON { (response) in | |
completion(response.data,response.error) | |
print("========> API: \(url)") | |
print("========> API: \(response)") | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment