tags:

views:

359

answers:

2

Hi,

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.

+3  A: 

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

Adam Rosenfield
Thanks. Any idea how to initiate a connection if one doesn't exist? For example, if the wifi has been turned off due to inactivity. Will NSURLRequest take care of this?
Dave
There is no way to programatically turn WiFi on (or plane mode off). I would suggest an easier solution of failing gracefully and apologising.
Roger Nolan
+2  A: 

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.

Roger Nolan