Antonio Murgia
Antonio Murgia

Reputation: 285

Xcode iPhone Programming check if a server is online

My app has to connect to a server, but sometimes when I test my application I don't have my server online, so the app remains stuck when opening. How I can test programmatically if the server is online? Is there something like ping so i can verify the state of the server and then doing the normal work or not if it is offline? Thank you!

Upvotes: 2

Views: 2309

Answers (2)

GoZoner
GoZoner

Reputation: 70215

Use [NSURLRequest + requestWithURL:cachePolicy:timeoutInterval:] with a timeoutInterval. Then your NSURLConnectionDelegate will get a callback if the request times out.

Upvotes: 0

Frank Schmitt
Frank Schmitt

Reputation: 25775

Take a look at Apple's Reachability example (you are encouraged to use it in your App Store-submitted apps).

Upvotes: 4

Related Questions