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.