iOS - Increase timeout for AFHTTPRequestOperationManager

后端 未结 5 947
被撕碎了的回忆
被撕碎了的回忆 2021-02-04 09:11

I\'m downloading JSON data from a very slow server. It takes about a minute to get a resoonse from the server. I use AFNetworking library and my code throws \"The request timed

5条回答
  •  心在旅途
    2021-02-04 09:59

    Actually, the value of timeoutInterval property is ignored - I've checked by debugging the method requestWithMethod:URLString:parameters:error:

    I managed to subclass and override the method (Swift)

    class RequestSerializer: AFHTTPRequestSerializer {
    
        override func requestWithMethod(method: String!, URLString: String!, parameters:AnyObject!, error: NSErrorPointer) -> NSMutableURLRequest {
                var req = super.requestWithMethod(method, URLString: URLString, parameters: parameters, error: error)
                    req.timeoutInterval = self.timeoutInterval
                    return req
        }
    }
    

提交回复
热议问题