gpt4 book ai didi

ios - 模块 'Alamofire' 没有名为 'SessionManager' 的成员

转载 作者:行者123 更新时间:2023-12-03 23:43:17 27 4
gpt4 key购买 nike

为什么我收到此错误,我没有。我已经在使用 Alamofire 5 时将 Alamofire 更改为 AF。请指导有什么问题和需要更改的地方。下面是我收到错误的代码:

 private func callAlamoFireFormalData(makeThisFunction : @escaping (AFDataResponse<Any>)->Void )
{
AF.request(url, method: httpMethod, parameters: paramters, encoding: encoding, headers: HTTPHeaders(self.headers ?? [:]))
//.validate(statusCode: 200..<300)
.responseJSON { response in

//print("\(response.response?.statusCode)")
guard response.response?.statusCode != 401
else{

Alamofire.SessionManager.default.session.getAllTasks { tasks in
tasks.forEach { $0.cancel() }
}
Helper.setApiToken(token: "")
Helper.removeUserInfo()
if var topController = UIApplication.shared.keyWindow?.rootViewController {
if let presentedViewController = topController.presentedViewController
{
topController = presentedViewController
topController.present(UIStoryboard.init(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "InitialNAV"), animated: true, completion: nil)
}

// topController should now be your topmost view controller
}
// Alamofire.pause()
return
}

switch response.result
{
case let .failure(error):

print(error)
self.serverResponse.error = true
self.serverResponse.message = String.serverError
self.serverResponse.content = nil
self.serverResponse.statusCode = response.response?.statusCode
makeThisFunction()

case .success(let value):

let json = JSON(value)
self.serverResponse.error = json["error"].boolValue
self.serverResponse.message = json["message"].stringValue
self.serverResponse.content = json["content"]
self.serverResponse.statusCode = response.response?.statusCode
makeThisFunction()

}
}

}

最佳答案

SessionManager类本质上重命名为 Session在 Alamofire 5 中。所以你可以用这个替换你的实现:

Alamofire.Session.default.session.getAllTasks { tasks in
tasks.forEach { $0.cancel() }
}
更新 :正如@JonShier 在评论中提到的,取消所有请求的正确方法是调用 SessioncancelAllRequests(completingOnQueue:completion:)功能:
Alamofire.Session.default.cancelAllRequests()

关于ios - 模块 'Alamofire' 没有名为 'SessionManager' 的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64494823/

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