I have an iPhone application in which I have a request which works fine on wifi and with all network carriages but one carriage. On this carriage, if I use ASIHttpRequest, it gives me the below error:
ASIHTTPRequest request_didFail: Error Domain=ASIHTTPRequestErrorDomain Code=1 "A connection failure occurred" UserInfo=0xd54e2f0 {NSUnderlyingError=0xd502de0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error 2.)", NSLocalizedDescription=A connection failure occurred}
If I use AFNetworking it returns below error:
NSLocalizedDescription = "Could not connect to the server.";
NSUnderlyingError = "Error Domain=kCFErrorDomainCFNetwork Code=-1004 \"Could not connect to the server.\" UserInfo=0xdc98630 {NSErrorFailingURLKey=https://sitename.com, NSErrorFailingURLStringKey=https://sitename.com, NSLocalizedDescription=Could not connect to the server.}";
First of all, what could be the reason of this error assuming it only happens for a specific carrier? Second, as the request works with everything but this carriage, it seems hard to debug, so how can I debug it to find the exact problem?
Thanks
It turned out that the problem was with this specific telco. Without changing the code, it started to work again after some time.
For the answer to this question, I can say that the reason could be about some proxy thing that is made by the telco and we tried to debug it by applying different proxy tests.
Related
I need to determine no internet exception when connecting to server without network. But on iOS I get IOException(On Android exception is ConnectException).
The message of exception contains this error message:
Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo={NSUnderlyingError=0x10bc06330 {Error Domain=kCFErrorDomainCFNetwork Code=-1009 "(null)" UserInfo={_kCFStreamErrorCodeKey=50, _kCFStreamErrorDomainKey=1}}, NSErrorFailingURLStringKey=http://..., NSErrorFailingURLKey=http://..., _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=50, NSLocalizedDescription=The Internet connection appears to be offline.}`
I can parse this message and check if it contains Code=-1009. But, is there a more elegant way to check NSError from JavaLangException?
Unfortunately, there currently isn't a better way. We tried extending changing java.lang.Throwable's superclass to NSException, but that caused more problems than it solved. It also doesn't make sense to define new exception classes for each iOS networking error code, as that would increase the size of each app that uses j2objc. Consider using something like: if (exception.getMessage().contains("NSURLErrorDomain Code=-1009")) ... or define a isConnectionOffline(Exception e) method that does this check as well as one for Android.
You could file an enhancement request for some sort of NSURLErrorDomain exception wrapper, which could make these errors easier to decipher. Better yet, we love contributions if you come up with something useful. ;-)
Generally, while performing GET or POST calls in iOS using dataTaskWithRequest or sendAsynchronousRequest we use to face network related errors with error codes like,
NSURLErrorNotConnectedToInternet = -1009
NSURLErrorCannotConnectToHost = -1004
NSURLErrorTimedOut = -1001
In my case i'm disconnecting the internet and performing service calls. So, the expected error code is "NSURLErrorNotConnectedToInternet = -1009". But, its throwing "NSURLErrorCannotConnectToHost = -1004" like below,
Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the
server." UserInfo=0x1700f0e00 {NSUnderlyingError=0x170255e70 "The
operation couldn’t be completed. (kCFErrorDomainCFNetwork error
-1004.)", NSErrorFailingURLStringKey=https://example.com/reg,
NSErrorFailingURLKey=https://example.com/reg, _kCFStreamErrorDomainKey=1,
_kCFStreamErrorCodeKey=51, NSLocalizedDescription=Could not connect to the server.}
So, how to get the exact error status while using dataTaskWithRequest or sendAsynchronousRequest.
As a rule, IIRC, the OS sends "not connected to Internet" only in two situations:
The network is determined to be nonfunctional after:
One or more URL requests fail and
The OS tries to probe a well-known captive-portal-detection URL and
That request also fails
No interface has an IP address
Including any connected VPNs
Excluding loopback interface
Up until the system reaches that state, the failures you see will be "cannot connect to host", because that's all the OS knows for certain.
As a rule, your app should interpret these in the same way — by using reachability to determine when to try again, then trying again when reachability changes.
I am using AfNetworking 1.0 into my app.I have created a singleton class of AFHTTP Client.
So all the API's are place in the same class.
I am getting a very wierd issue.
For eg: Let say, i have requested for some data from server.But the internet connection has lost.
So the failure block get's called.
m getting the following error:
Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo=0x797dcc70 {NSErrorFailingURLStringKey=https://testing.com?searchText=s&pageSize=10&pageNumber=5, _kCFStreamErrorCodeKey=57, NSErrorFailingURLKey=https://testing.com?searchText=s&pageSize=10&pageNumber=5, NSLocalizedDescription=The Internet connection appears to be offline., _kCFStreamErrorDomainKey=1, NSUnderlyingError=0x7aa367e0 "The Internet connection appears to be offline."}
But if i try to get the status code using following code:
NSLog(#"Status code %d",[operation.response statusCode]);
m getting Status Code as "0".
Can you please explain,why i am getting Status code as "0"?
I have to handle the error,depends on HTTP Status Code.So what is the best way to get this done?
(the same way which i am doing or is there any other way.)
In this case you can't use the status code because there isn't one. The status code comes from the server and in this case the client has not been able to contact the server.
You should use the error domain and code to handle this case.
My blog app was working fine, using ASIHTTPRequest and GDATAXML to parse the XML file. I tried adding a Today Extension, but now it won't properly parse the XML file. Only other changes I tried making was using Cocoapods to add a different parser to it, but I have since deleted all files that I had added. Now all I get is:
Error: Error Domain=ASIHTTPRequestErrorDomain Code=1 "A connection failure occurred" UserInfo=0x7a953f90 {NSUnderlyingError=0x79eb1180 "The operation couldn’t be completed. Socket is not connected", NSLocalizedDescription=A connection failure occurred}
I am getting this error code when using 'MKMapView' on the iPhone 4:
Could not determine current country code: Error Domain=GEOErrorDomain Code=-2 "The operation couldn’t be completed. (GEOErrorDomain error -2.)"
The map loads fine with coordinates etc, but this gets logged.
Any ideas what is causing it?
I got this today on my iPad4-Wifi.
Reading more of the message, it stated that it had o internet connection.
Sure enough, the iPad lost connection to the wifi for some reason.
I reselected our wifi network, retried the test and it worked.