AlamoFire does not respect timeout interval

前端 未结 6 2072
离开以前
离开以前 2021-02-01 14:03
class APIClient {
    var user = User()
    let alamoFireManager : Alamofire.Manager?
    let center = NSNotificationCenter.defaultCenter()


    init(){
        let con         


        
6条回答
  •  忘掉有多难
    2021-02-01 14:16

     init(){
        let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
        configuration.timeoutIntervalForResource = 4
        configuration.timeoutIntervalForRequest = 4
        self.alamoFireManager = Alamofire.Manager(configuration: configuration)
        self.alamoFireManager!.request(.POST, CONSTANTS.APIEndpoint+"/test", parameters: parameters).responseJSON {
                        (req, res, json, error)  in
                        if let json = self.handleAPIResponse(req, res: res, json_data: json, error: error){
                        }
                    }
    }
    

    Use self.alamoFireManager!.request in the same init function , timeout delay is only for the request not for the whole function. may be it can help.

提交回复
热议问题