iPhone reachability checking

Posted by Sneakyness on Stack Overflow See other posts from Stack Overflow or by Sneakyness
Published on 2009-12-07T17:46:09Z Indexed on 2010/05/25 15:31 UTC
Read the original article Hit count: 333

I've found several examples of code to do what I want (check for reachability), but none of it seems to be exact enough to be of use to me. I can't figure out why this doesn't want to play nice.

I have the reachability.h/m in my project, I'm doing

#import <SystemConfiguration/SystemConfiguration.h>

And I have the framework added. I also have:

#import "Reachability.h"

at the top of the .m in which I'm trying to use the reachability.

Reachability* reachability = [Reachability sharedReachability];
[reachability setHostName:@"http://www.google.com"];    // set your host name here
NetworkStatus remoteHostStatus = [reachability remoteHostStatus];

if(remoteHostStatus == NotReachable) {NSLog(@"no");}
else if (remoteHostStatus == ReachableViaWiFiNetwork) {NSLog(@"wifi"); }
else if (remoteHostStatus == ReachableViaCarrierDataNetwork) {NSLog(@"cell"); }

This is giving me all sorts of problems. What am I doing wrong? I'm an alright coder, I just have a hard time when it comes time to figure out what needs to be put where to enable what I want to do, regardless if I want to know what I want to do or not. (So frustrating)

Update: This is what's going on. This is in my viewcontroller, which I have the

#import <SystemConfiguration/SystemConfiguration.h>

and

#import "Reachability.h"

set up with. This is my least favorite part of programming by far.reachability problems


FWIW, we never ended up implementing this in our code. The two features that required internet access (entering the sweepstakes, and buying the dvd), were not main features. Nothing else required internet access.

Instead of adding more code, we just set the background of both internet views to a notice telling the users they must be connected to the internet to use this feature. It was in theme with the rest of the application's interface, and was done well/tastefully. They said nothing about it during the approval process, however we did get a personal phone call to verify that we were giving away items that actually pertained to the movie. According to their usually vague agreement, you aren't allowed to have sweepstakes otherwise.

I would also think this adheres more strictly to their "only use things if you absolutely need them" ideaology as well.

Here's the iTunes link to the application, EvoScanner.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c