Question

My question might have a very easy answer but I am not going anywhere on Google with the keywords I am using. Let me explain, it surely will be clear to one of you.

In my app, I am uploading a string to a server. If the connection is successful, the user gets a "done" message and if not, I tell him what to do next.

I was testing this afternoon with the "no network simulator" and it works well, but I had to wait may be 90 seconds before I get the message "no connection available". I don't know for how long it tries to connect in real life, but I found the wait really annoying and wouldn't like my user to be in such a situation.

My question is : I want the app to try and connect to the server for say 20 seconds and if after that time it hasn't succeeded, it stops trying and the user decides if he wants to try a second time or not ?

My apologies in advance, English isn't my mother tongue.

Thank you for pointing me to the right direction.

Was it helpful?

Solution

You should set timeout interval in session configuration

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
configuration.timeoutIntervalForRequest = 20;
configuration.timeoutIntervalForResource = 20;
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];

// in case if you are using AFNetworking
// AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithSessionConfiguration:configuration];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top