I am working on my first iOS app and to make network calls I am using Alamofire. It is nice and easy. I implemented Alamofire in separate class, lets call it WebserviceHelper. now I was using this class from all over the application. but now I want to set the timeout.
here is the snippet on how I have made function in WebserviceHelper class.
static func requestService(methodName: String, method: HTTPMethod, parameters: Parameters, headers: HTTPHeaders? = nil, showLoaderFlag: Bool, viewController: UIViewController, completion: @escaping (_ success: JSON) -> Void) {
let reachability = Reachability()!
/*
checking for internet connection
*/
if(reachability.connection != .none) {
/*
Showing Loader here
*/
if(showLoaderFlag){
ViewControllerUtils.customActivityIndicatory(viewController.view, startAnimate: true)
}
print("Web Service Url - \(Common.URL+methodName)")
print("Parameters - \(parameters)")
/*
Request configure
*/
Alamofire.request(Common.URL+methodName, method: method, parameters: parameters, encoding: JSONEncoding.default, headers: headers) .responseJSON { response in
here you can see it is quiet easy to use it. I have used many ways to set timeout but it is not working for me. this is what I tried. and also this link but nothing really worked for me.
Can you guys help me in setting Timeout using Alamofire.