ios - 网络连接从 Alamofire 丢失

标签 ios swift alamofire

我在我的项目中多次遇到这个错误,这让我很恼火,因为我有完整的互联网连接,尽管我反复遇到这个错误。

enter image description here

解决方案是什么...?

我正在使用

Swift - 3.3

Alamofire - 4.7.3

API调用代码:

class  func post(_ URL: String, withParams params: [String : AnyObject], onView parentView: UIViewController, hnadler completion: @escaping ([AnyHashable: Any]!) -> Void) {
        var URLString  = String()
        URLString = APIConstants.kServerURL + URL
        var headers = [String: String]()
        headers["Content-Type"] = "application/x-www-form-urlencoded"
        
        Alamofire.request(URLString,method: .post, parameters: params , headers : headers)
            .validate(contentType: ["application/vnd.api+json"])
            .responseJSON { response in
                switch response.result {
                case .success( _):
                    var completionVarible = [NSObject : AnyObject]()
                    completionVarible = response.result.value as! [AnyHashable: Any]! as [NSObject : AnyObject]
                    completion(completionVarible)
                case .failure(let error):
                    self.handleFailureResponse(Error: error as NSError?, parentView: parentView)
                }
        }
    }

最佳答案

如果警报立即出现,您可以尝试将缓存策略更改为 .reloadIgnoringCacheData

关于ios - 网络连接从 Alamofire 丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54069361/

相关文章:

iphone - UIImageView 不同区域的 UIGesture 识别

iOS - 禁用 Alamofire 缓存参数

ios - 验证 Realm 是否在 iOS 上加密的正确方法?

ios - 向下滚动和向上滚动后 UITableViewCell 中的图像发生变化

ios - 在 Swift 中创建日历

ios - NSArray 上的 Swift 内存泄漏

swift - 如何使用alamofire在ios中传递访问 token

swift - Alamofire,对象映射器, Realm : Nested Objects

ios - Objective-C:如何在单个 UITableViewCells 中列出文件?

arrays - 打印按钮集合中的整数数组,Swift