gpt4 book ai didi

ios - 使用 Alamofire 上次异步 HTTP 请求的响应数据

转载 作者:行者123 更新时间:2023-11-29 00:58:28 25 4
gpt4 key购买 nike

我目前正在使用 Alamofire 向我的服务器发出异步 http 请求以取回一些数据。但是,我大约同时向服务器发出 3 个请求,我只想使用我发出的最后一个请求中的数据。但是,我遇到了第 2 个请求在第 3 个请求之后完成的问题。因此,它导致使用前 2 个请求的数据。

    HttpService.makeGetRequestWithHeader(AppEndPoint.driverLocation, params: params, completionHandler: {(responseData, error) -> Void in
if let data = responseData {
self.cars.removeAll()

let driverLocationListResponse: DriverLocationListResponse = DriverLocationListResponse.fromDictionary(data)
var driverCars: [DriverCar] = []
for driver in driverLocationListResponse.driverLocationList {
let driverCar: DriverCar = DriverCar(driverId: driver.driverId!, latitude: driver.latitude!, longitude: driver.longitude!)
driverCars.append(driverCar)
}

self.addCars(driverCars)
}
})

有谁知道如何解决这个问题?谢谢!

最佳答案

保留对此请求的引用并在运行之前取消它。

关于ios - 使用 Alamofire 上次异步 HTTP 请求的响应数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37333276/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com