【发布时间】:2019-06-25 23:44:48
【问题描述】:
我正在开发我的第一个 iOS 应用程序并使用 Alamofire 进行网络通话。这很好也很容易。我在单独的类中实现了 Alamofire,我们称之为 WebserviceHelper。现在我在整个应用程序中使用这个类。但现在我想设置超时。
这里是关于我如何在 WebserviceHelper 类中创建函数的 sn-p。
static func requestService(methodName: String, method: HTTPMethod, parameters: Parameters, headers: HTTPHeaders? = nil, showLoaderFlag: Bool, viewController: UIViewController, completion: @escaping (_ success: JSON) -> Void) {
let reachability = Reachability()!
/*
checking for internet connection
*/
if(reachability.connection != .none) {
/*
Showing Loader here
*/
if(showLoaderFlag){
ViewControllerUtils.customActivityIndicatory(viewController.view, startAnimate: true)
}
print("Web Service Url - \(Common.URL+methodName)")
print("Parameters - \(parameters)")
/*
Request configure
*/
Alamofire.request(Common.URL+methodName, method: method, parameters: parameters, encoding: JSONEncoding.default, headers: headers) .responseJSON { response in
在这里您可以看到它非常易于使用。我使用了很多方法来设置超时,但它对我不起作用。 this 是我尝试过的。还有this 链接,但没有什么对我有用。
你们能帮我用 Alamofire 设置超时吗?
【问题讨论】:
-
相关链接在最新版本中无效。请不要将其标记为最新版本
-
Mayur Karmur 是正确的。但是,我还想补充一点,您不应该将可达性用作网络调用的预检查。 Apple 特别反对这种做法,因为可达性并不那么精确。
-
Jon Sheir 我应该用什么来代替可达性