iPhone Reachability - iphone

I am trying to cover my bases with reachability so that my app doesn't get rejected by the App Store. I am familiar with the Reachability class that Apple provides in sample code. My question is, how best to implement this. I've seen that checking if the WWAN is accessible is not always best because it may be turned off for power consumption. So do I have to somehow enable it before checking for a connection. Just looking for steps to take. My app doesn't need a constant connection. It does some polling on a given interval that will require a connection and makes other various requests. Just trying to figure this out so I don't get rejected. Any help would be great.
Edit: Will reporting errors NSURLDomainError errors suffice for reporting reachability? It currently displays No Internet Connection and Can't Find Host. Seems that this is the type of information that the reachability example is used for.

Assuming that your application needs a connection to the internet, you could check the connectivity to a website that is always up (like e.g. google.com). The reachability sample code already contains a method to do just that.
I have not worked with the Reachability API enough to know how it reacts to the system switching off the WWAN for power saving. The only thing that comes to my mind is that you could try to establish a connection to the network so the system switches the WWAN on. Then you can run your reachability code to check what kind of connection you are working with. As said, I have not tried it, just an idea.

Related

Troubleshooting to connect and disconnect to network

Suppose I have a application which fetch data from network and then showing those data in application. But sometimes internet becomes disconnected so I am showing message that 'Internet not available'. But I want to keep user busy with the application. So I want to do following things but there are some problem in implementation.
1) When network disconnected I want to show message 'network disconnect' and I want to store all data in db.
Problem: How will I know network is not available without happening any event?
2) And when network is connected I want to fetch data and store in buffer.
Problem : Same, how will I know network is available rightnow?
This is quite common question and is best solved using Reachability class.
You can find a nice manual here: Testing Network Reachability
And a quick answer is the accepted answer here:
iPhone reachability checking
But be aware that it's best to check for host availabiility. I tested this code when device was connected to AdHoc WiFi (with no internet connectivity) and the result was: internet available via WiFi. So if you want to be sure - use host status.
EDIT: and this is probably the best example on SO (answer from iWasRobbed):
How to check for an active Internet connection on iOS or OSX?

How to check if internet is active and it works? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Easiest way to determine whether iPhone internet connection is available?
Hi guys,
I'm developing an iPhone app. It works totally with internet.
When I run my app, how can I check if internet is active and it works correctly?
And if it's not I would to show a popup.
Thanks.
Be aware that Reachability is (in my opinion) a misnomer.
Reachability, including reachabilityWithHostName (as in Apple's example) only indicates whether the device has an available internet connection with which to reach the outside world.
IMPORTANTLY: it does not indicate whether the specified host is actually up and running.
To find out whether the remote host is actually up and running, you'll need to initiate a connection to the remote host and handle a timeout in the case that it is not.
There's no such thing as "Internet". There exists large number of computers and other hardware, linked together. Now, if you need a particular host, you can ping it (also in code, don't know if iPhone lets you do this, though). If you need to ensure that particular service on the particular host is up and running, your only option is to send a request and check the response.
Another vote for Apple's reachability example code here.
Note it's important to get this right - apparently it's grounds for app rejection if you provide a misleading error message relating to networking. For example if you say you could not reach myhost.com when in fact it's because there is no network connection.

iPhone Reachability gives a wrong network status

I used the Reachability code provided by Apple sample code. When I used cellular data network, it could detect that network. However, once I turned it off and re-run my app again, the Reachability still gave me ReachViaWMAN (NetworkStatus) similar to the cellular network. I tried reboot my iPhone with the celluar data turned off, and ran my app again. The result is the Reachability couldn't reach a host.
I'm really confused now. How to fix this problem?
The Reachability code is just sample code. There are a number of bugs in it. I remember a bug where it failed when a VPN was used for example. I know this code is used pretty much by everyone but Apple never intended it to be some sort of official API.
You are far better off understanding how the underlying APIs work and use those directly in your app. They are not difficult to use and you will catch a number of situations that Reachability does not deal with correctly.

iPhone: Reachability for wireless where actual internet is not needed

Anyone have an idea on how I could check for a wifi connection where I don't necessarily need to connect to the internet? I've implemented wifi multiplayer in a game I'm working on, so I want to make sure and let the user know if there's no connection when they are trying to use that mode. The Reachability sample code seems to only work for situations where you have a host you are trying to route to. Since I have no knowledge of how other people's wifi will be set up, I need to be able to check for wifi without trying to route to a specific place.
Edit: Nevermind, I've got it. Just took a little more digging in the Reachability code.
You can check that you reach the access point (which will almost always be the iPhone's gateway, Internet or not). 802.11b/g/n with a route to the Internet and without a route to the Internet will appear exactly the same to the phone -- or any device, for that matter.
I could foresee asking the phone for its gateway and attempting to talk to it (ping, maybe?) but I'm unfamiliar with the Reachability approach. If indeed you have figured it out, I'd love to see an answer.
There is a method in the reachability class that returns an instance for wifi. I think it was called reachabilityForLocalWiFi.

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.
Check out the Reachability sample. It has a bunch of functions for testing network connectivity.
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.