ios - Alamofire 后台获取不处理更进一步的请求
问题描述
我想使用 执行后台提取performFetchWithCompletionHandler
,显然所有以前的解决方案都对我不起作用。
奇怪的是我的第一个请求是好的,但下一个不是。
我尝试使用单例 SessionManager,我还尝试将所有 Alamofire 请求出列到后台线程,并更改了URLSessionManager
with URLSessionConfiguration.background(withIdentifier: "com.test.background")
。
group.enter()
api.getClimateStateData(carId: carId, completion: { [weak self] response in
guard let strongSelf = self else { return }
climateModel = strongSelf.sortDataFromError(data: response)
group.leave()
})
func getClimateStateData(carId: Int, completion: @escaping (ServiceResponse<ClimateStateModel>) -> Void) {
let header: HTTPHeaders = ["User-Agent": UserAgentHelper.fullUserAgentString]
request("/api/1/vehicles/\(carId)/data_request/climate_state", method: .get, parameters: nil, encoding: nil, headers: header).responseData { [weak self] response in
guard let strongSelf = self else { return }
completion(strongSelf.completionResponse(response))
}
}
@discardableResult private func request(
_ path: String,
method: HTTPMethod,
parameters: Parameters? = nil,
encoding: ParameterEncoding? = nil,
headers: HTTPHeaders? = nil)
-> DataRequest {
let userEncoding = encoding ?? self.defaultEncoding
print("Asking: " + path)
return Service.sessionManager2.request("\(API)\(path)", method: method, parameters: parameters, encoding: userEncoding, headers: headers).validate()
}
我希望满足这些要求。
谢谢你的时间!
解决方案
我的错,这是由于self
= nil。
由于某些原因,self
被 deinit。
推荐阅读
- python - 如何在python中更新字典中的列表值
- jira - 关于问题更新事件的 JIRA 问题链接
- mysql - Orbeon Forms 2018.1.1 CE 和 MySQL:在任何已创建表单的摘要页面上收到“执行搜索错误”
- azure - 将 arm 模板部署到 azure 时出现内部服务器错误
- azure - 在 Azure 中保护 api 到 api 连接
- python-3.x - 多线程爬虫运行一段时间后越来越慢
- python - 有什么方法可以更快地运行此代码?
- flurry - Flurry Analytics 用户路径通过事件参数
- spring-mvc - log4j 没有在我的控制器中显示映射的 url
- java - Jersey Web 服务 ExceptionMapper Oracle EPM HFMException