In the application development process, the network request is often required, in the process of the network request, the general third-party network frame timeout time is longer than 15 seconds;
So, how do we specify the time-out for the request?
In Swift's world, the more famous network is Alamofire Githut address: Https://github.com/Alamofire/Alamofire
Then, when using Alamofire, set the Alamofire request time as follows:
This example code is as follows:
1var alamofiremanager:manager?2 //to set the time-out for a request3Let config =nsurlsessionconfiguration.defaultsessionconfiguration ()4Config.timeoutintervalforrequest =5 //seconds5 6Self.alamofiremanager =Manager (configuration:config)7 8 //Set parameters such as Urlstr paramdic9self.alamofiremanager!. Request (Method.get,urlstr, Parameters:paramdic,Ten Encoding:ParameterEncoding.URL) One. Responsejson {(_, _, JSON, _)inch A}
Welcome to criticize and correct!
[Swift work tips] using Alamofire to set the request timeout (timeout) time when making a network request