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)
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:
No problem with Internet connection
"App Transport Security Settings" are correct and server's using https (I also tried "NSAllowsArbitraryLoads=true" but that didn't help)
APIs working fine
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 "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.}
Any suggestions?
UPDATED
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.
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.
The issue goes away with HTTP/1.1 and it's also working with HTTP/2 in Nginx version up to 1.9.14.
Nginx 1.11.0 Mainline is now available with the fix included mentioned earlier in this topic;
Change: HTTP/2 clients can now start sending request body
immediately; the "http2_body_preread_size" directive controls size of
the buffer used before nginx will start reading client request body.
I tested it and for me this release now works correctly again.
This seems like a confirmed bug in nginx 1.10. An issue about it can be found on the bug tracker of nginx at https://trac.nginx.org/nginx/ticket/979. The actual issue can be found at https://trac.nginx.org/nginx/ticket/959
You might want to consider switching to the 1.9 branch which has releases which do work. Hopefully nginx will release a 1.10.1 version soon which does not have this bug.
The issue actually only occurs on iOS; Android, Windows and OSX itself seem to have no problems negotiating a valid http2 connection.
I can also confirm that the nginx 1.9.15 not works correctly. Some calls always got "Could not connect to the server", and after revert to nginx 1.9.12 everything works fine.
These are the steps that I would try to follow:
1) test my app in the simulator and device
2) look if https is really needed instead of http
3) configure an alamofire manager and change timeout (for this step i
write some code):
var alamofireManager = Alamofire.Manager.sharedInstance
let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
configuration.HTTPMaximumConnectionsPerHost = 10
configuration.timeoutIntervalForRequest = 30
configuration.timeoutIntervalForResource = 30
alamofireManager.delegate.taskWillPerformHTTPRedirection = nil
(so whit this last step the next alamofire calls can be for example: alamofireManager.request(etc....)
4) test with hard link like http://www.google.com, if the same thing
dont happened nothing around your swift code are incorrect, try to
set your web server parameters..
Problem solved!!!
versions:
1. Nginx version: 1.10.2
2. IOS version: 9.3.2
When the config like this:
listen 443 ssl;
Have the same problem like you.
But !!!
When the config like this:
listen 443 ssl http2;
Problem solved!!
Related
same issue, other person: https://github.com/signalapp/Signal-iOS/issues/2282
We've checked out the Signal-iOS repository and we're trying to make it connect to another server. We're running an instance of the server at signal.appcraft.nl. We've modified the defines in SignalServiceKit/src/TSConstants.h to match our server and we've changed the domains in App Transport Security Settings in /Signal/Signal-Info.plist
We also cloned the Android app and that one we managed to got working just fine. The iOS app seems not to be able to connect to the internet at all without a clear error. The first HTTP call that is done is GET https://signal.appcraft.nl/v1/accounts/sms/code/<MYNUMBER>?client=ios. When we invoke that URL using curl, we get a response (and SMS) just fine. From the app, we receive a Signal was unable to connect to the internet. Please try from another WiFi network or use mobile data. error. We also changed NSAllowsArbitraryLoads to Yes.
We've added a breakpoint in /Signal-iOS/Pods/AFNetworking/AFNetworking/AFHTTPSessionManager.m:292
# /Signal-iOS/Pods/AFNetworking/AFNetworking/AFHTTPSessionManager.m:292
(lldb) expr error
(NSURLError *) $3 = 0x00000001c0244800 domain: #"NSURLErrorDomain" - code: 18446744073709550617
Please advise
[carc] CAReportingClient.mm:320:-[CAReportingClient sendMessage:category:type:reporters:]_block_invoke: The operation couldn’t be completed. No valid RTCReporting and the session was started
i have the same problem with using google stun:stun:stun.l.google.com:19302
i think the problem is caused by the stun/turn server.
i solve and test it successfully with applying a free turn server in http://numb.viagenie.ca/cgi-bin/numbacct
and in swift i just add the
RTCIceServer(urlStrings: ["turn:numb.viagenie.ca:3478"], username: "YourUserName", credential: "yourPassword")
into iceServers list of webrtc,
this works for me, at least prove my swift side is correct(i am iOS developer), all the rest is the turn/stun server side.
My iOS app use RestKit framework for implementing RESTful web services client.
Sometimes, I have a problem when I call my server from my application.
The request is not sent and it fails at the end of the expiration with this error:
Error Domain=NSURLErrorDomain Code=-1001 "The request timed out."
At the first openning, it is impossible to reproduce this.
The problem occurs when the application is put into the background and it restarts 10 minutes later or more (it does not produce every time). At this point, there is no server side call .
Then, the only way to solve this problem is to force-quit the application.
We checked there is no error of url, of header, etc ...
HELP ME :'(
Try to set time interval like
[manager.requestSerializer setTimeoutInterval:yourTimeInterval];
I tried to connect IBM AppCenter 6.2.0.01.20141013-1735 on iOS 6/8.1 (enabled SSL)
After I clicked Login btn, app showed Loading view forever (no fail/success/timeout response).
I checked device log:
IBMAppCenter[1385:29127] [Appcenter][CordovaPlugin][INFO]: Query login
user name:admin server:https://example.net:9443/applicationcenter
Then I disabled network, Application hided loading and showed "no network" message.
I checked log again then saw this:
2015-03-31 10:07:13.191 IBMAppCenter[1385:29127]
[Appcenter][CordovaPlugin][ERROR]: Query login admin on
https://example.net:9443/applicationcenter/FAILED
2015-03-31 10:07:13.191 IBMAppCenter[1385:29127] [Appcenter][General][ERROR]:
Error handler, http status: null "Error Domain=NSURLErrorDomain
Code=-1009 "The Internet connection appears to be offline."
UserInfo=0x7c8c2830
{NSErrorFailingURLStringKey=https://example.net:9443/applicationcenter/service/auth,
_kCFStreamErrorCodeKey=57, NSErrorFailingURLKey=https://example.net:9443/applicationcenter/service/auth,
NSLocalizedDescription=The Internet connection appears to be offline.,
_kCFStreamErrorDomainKey=1, NSUnderlyingError=0x7c8c0890 "The Internet connection appears to be offline."}"
2015-03-31 10:07:13.192 IBMAppCenter[1385:29127] [Appcenter][General][ERROR]: Error handler, displayed message:
"Connection failed. Check your connection details (The Internet
connection appears to be offline.)."
maybe it was connecting to /service/auth...
I tried on Android, it works fine.
Also tried with no-ssl, it works fine on both Android/iOS.
my SSL was verified by GoDaddy G2.
I am stuck over here and could not find any way out.
This may be related to the way you have installed the GoDaddy-issued certificate.
First,
Make sure it upholds to the required standards for using a certificate: IBM AppCenter 6.2.0 + SSL on iOS - shows loading view forever when connect to Server (no response fail/success/timeout))
Second,
Verify you have properly installed it. That is, make sure you did not install it via the Mobile Safari browser, as it won't be available to apps that way (see above link).
I am using the ASIHttpRequest library for IOS to attempt to download a zip file from my iPad application and it all works fine. However, I am trying to simulate a request timeout and handle this situation appropriately. I am using a trial version of CharlesProxy to attempt to simulate a timeout and Im also killing my tomcat server. In the situation where I am killing the tomcat server in the middle of the zip download, the ASIHttpRequest is still receiving a 200 response, with the error object begin set to nil even though the download is not complete and is not successful.
I have checked the downloadComplete property on the ASIHttpRequest request object and it is set to YES.
Has anyone else noticed this?