I'm having a weird problem when i consume my API from my app. Sometimes, for no reason, the request is just not sent, and it fails at the end of the time-out with the following error:
Error Domain=NSURLErrorDomain Code=-1001 "The request timed out."
I have tried many API such as NSURLConnection
delegates, NSURLSession
and NSURLConnection.sendSynchronousRequest
without success.
Here is a sample project i have made to highlight the issue. ConnectionBugApp
Here are the steps to reproduce:
- Run the app in Xcode and stop debug just so the app is on your phone
- Open the app, click Test Connection (it succeeds, loading wheel stops spinning right after)
- Go to other apps like facebook/twitter/network games (somes that are a bit heavy) and switch to airplane mode a few times
- Go back to my app and click Test Connection (loading wheel never stops)
A few details that might help:
If I use my server IP instead of my domain name, it succeeds
Issue only appears when on the LTE/4G network
Any ideas or workaround would be greatly appreciated ! Feel free to ask for more details.
Thanks
EDIT
I've edited the description a lot since i first posted it (hoping to make it cleaner and clearer), i'm sorry if some answers or comment don't really make sense anymore.