在没有连接的情况下,我将失败的请求附加到队列管理器(包含数组)
我正在呈现一个带有重试按钮的自定义弹出窗口。当按下重试按钮时,我想重试在无连接状态下无法发送的请求。可能有多个请求。
当我尝试retryRequestAlamofireSession类中的方法时,请求的任务状态保持在 initilazed 或 finish 状态,但必须恢复才能成功发送请求,我该如何解决这种情况?
拦截器接口.swift
public func didGetNoInternetConnection() {
let viewModel = AppPopupViewModel(title: L10n.AppPopUp.areYouOffline, description: L10n.AppPopUp.checkInternetConnection, image: Images.noInternetConnection.image, firstButtonTitle: L10n.General.tryAgain, secondButtonTitle: nil, firstButtonAction: { [weak self] in
guard let self = self else { return }
DispatchQueue.main.async {
self.retry()
}
}, secondButtonAction: nil, dismissCompletion: nil, dimColor: Colors.appGray.color.withAlphaComponent(0.8), showCloseButton: true, customView: nil)
DispatchQueue.main.async {
AppPopupManager.show(with: viewModel, completion: nil)
}
}
private func retry() {
guard let head = NetworkRequestStorage.shared.head else {
return
}
let …Run Code Online (Sandbox Code Playgroud)