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

Module 'Alamofire' has no member named 'SessionManager'

为什么我会收到此错误,我没有收到。我已经使用 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 { [=12=].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 class 在 Alamofire 5 中基本上重命名为 Session。所以你可以用这个替换你的实现:

Alamofire.Session.default.session.getAllTasks { tasks in
    tasks.forEach { [=10=].cancel() }
}

更新:正如@JonShier 在评论中提到的,取消所有请求的正确方法是调用SessioncancelAllRequests(completingOnQueue:completion:) 函数:

Alamofire.Session.default.cancelAllRequests()