如果先前的查询正在执行,则Alamofire队列请求

时间:2016-10-07 05:46:48

标签: ios swift alamofire

当我发送第一个请求然后再发送第二个请求时,Alamofire会取消第一个请求,并在-999取消时给出错误。 解决方法是什么,以便处理两个请求?

所以我想要做的是,用户点击按钮发送一个请求,然后在该请求完成用户再次点击该按钮之前。此行为取消了先前的请求,而我想要的是,当单击按钮并发送请求时,它应检查先前的请求是否已完成或仍在运行。如果它已完成,则请求应正常处理,但如果先前的请求未完成,则应等待请求完成,一旦完成,则应发送此请求

 self.alamoFireManager.request(request )
                    .responseJSON { response in

                        print(response.request)  // original URL request
                        print(response.response) // URL response
                        print(response.data)     // server data
                        print(response.result)   // result of response serialization
                        guard response.result.error == nil else {
                            // got an error in getting the data, need to handle it
                            print("error calling GET on page")
                            print(response.result.error!)
                            print("Failure")

                            if( response.result.error?.code == -999 )
                            {
                                print("Previous Query is still Executing")
                                return
                            }

0 个答案:

没有答案