应用启动后几秒内NSURLErrorDomain Code = -1004 [英] NSURLErrorDomain Code=-1004 for few seconds after app start up

查看:2799
本文介绍了应用启动后几秒内NSURLErrorDomain Code = -1004的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Alamofire API调用时遇到NSURLErrorDomain Code = -1004错误,
但是仅在应用启动后几秒钟(或者在应用启动时休息了几分钟之后打开并拨打电话)

I'm getting "NSURLErrorDomain Code=-1004" error with Alamofire API calls, but only for few seconds after app started (or took a rest for few minutes while the app's opened and make a call after that)

如果我在几秒钟后尝试拨打同一电话,一切正常。
我搜索了所有Stack Overflow问题并检查了以下所有可能的原因:

If I try to make the same call after few seconds, everything works fine. I searched all the Stack Overflow questions and checked all the possible causes below:


  1. 互联网连接没问题

  2. 应用传输安全设置是正确的,服务器使用https(我也尝试过NSAllowsArbitraryLoads = true但没有帮助)

  3. API工作正常

我的直觉是,获取网络设置需要几秒钟,当我在完成之前进行API调用时,它会立即失败。或者..我在背景中使用可能相关的Websocket?

My gut feeling is that getting the network settings takes few seconds and when I make an API call before that's done, it just fails immediately. OR.. I'm using a Websocket in background that could be related?


FAILURE:Error Domain = NSURLErrorDomain Code = -1004可以没有连接到服务器。 UserInfo = {NSUnderlyingError = 0x137d39380 {Error Domain = kCFErrorDomainCFNetwork Code = -1004(null)UserInfo = {NSErrorPeerAddressKey = {length = 16,capacity = 16,bytes = 0x100201bb341a9f540000000000000000},_ kCFStreamErrorCodeKey = -2200,_kCFStreamErrorDomainKey = 4}}, NSErrorFailingURLStringKey = [FILTERED],NSErrorFailingURLKey = [FILTERED],_ kCFStreamErrorDomainKey = 4,_kCFStreamErrorCodeKey = -2200,NSLocalizedDescription =无法连接到服务器。}

FAILURE: Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server." UserInfo={NSUnderlyingError=0x137d39380 {Error Domain=kCFErrorDomainCFNetwork Code=-1004 "(null)" UserInfo={NSErrorPeerAddressKey={length = 16, capacity = 16, bytes = 0x100201bb341a9f540000000000000000}, _kCFStreamErrorCodeKey=-2200, _kCFStreamErrorDomainKey=4}}, NSErrorFailingURLStringKey=[FILTERED], NSErrorFailingURLKey=[FILTERED], _kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2200, NSLocalizedDescription=Could not connect to the server.}

有任何建议吗?

更新

UPDATED

发现应用程序在启动时发出4个请求,其中1个或2个随机失败,我检查了Nginx访问和错误日​​志,并且根本没有记录失败的调用。

Found that app makes 4 requests on launch, and 1 or 2 of them randomly fails, and I checked Nginx access and error log and there's no log for the failed calls at all.

推荐答案

我们在Nginx 1.10.0(和1.9.15),iOS 9.3.1中使用带有TLS 1.2的HTTP / 2也有同样的问题。

We have the same issue here with Nginx 1.10.0 (and 1.9.15), iOS 9.3.1 using HTTP/2 with TLS 1.2.

这个问题在HTTP / 1.1中消失了,它也在Nginx版本中使用HTTP / 2到1.9.14。

The issue goes away with HTTP/1.1 and it's also working with HTTP/2 in Nginx version up to 1.9.14.

这篇关于应用启动后几秒内NSURLErrorDomain Code = -1004的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆