Dave
Dave

Reputation: 453

iPhone internet connectivity

I'm developing a game for the iPhone at the moment and I'd like to offer the player the option to submit their high scores to my server. The gameplay itself does not require internet connectivity.

What's the best way to handle this, just make the request and fail gracefully if there's no internet connection, or is there an API to request that the user connects to the internet?

I'm using NSURLRequest and NSURLConnection to submit the data.

I've searched the Apple docs and the only thing I've come across is the flag for the persistent wifi connection but that seems like overkill.

Any help is appreciated.

Upvotes: 1

Views: 571

Answers (2)

Rog
Rog

Reputation: 17170

NSURLConnection will do all you need. If there is a connection available (WAN or WiFi) it will do everything needed to set up the connection. If there isn't a connection when you try, simply store the high-score and upload it when your app is next launched.

Unless you want to provide detailed information about why a failure occured or provide imediate retry when the netwrok becomes available, complex reachability code (like the apple example) sounds like overkill for uploading a high-score table.

Upvotes: 2

Adam Rosenfield
Adam Rosenfield

Reputation: 400284

Check out the Reachability sample. It has a bunch of functions for testing network connectivity.

Upvotes: 3

Related Questions