Ahh… my article starts out with a hedge… a single word that could negate the value of this tutorial… theory! Apple has built a walled garden. It is their happy little nirvana, filled with thousands of apps and billions of downloads. Your apps are invited to this party, if you can get past the checklist. If you have an online app, there is one pesky requirement that could instantly thwart your dreams – reachability. Your app needs to test for Internet connectivity. If it doesn’t, it risks rejection!
I’ve read the online tutorials. I’ve searched the web. Bing, Google, Apple’s documentation… nothing made sense. I’m more familiar with web programming. I’m not used to this Objective-C stuff. Everything out there seemed needlessly complicated. My goal was simple… if Photics.com could not be reached, give the user an error. Apple is very picky about the user interface. They want to create a pleasant experience for their customers. I can’t say that I blame them. Their requirement makes a lot of sense. But the tutorials that I’ve read… I couldn’t make sense out of it.
1 2 3
<img src="http://photics.com/games/conquest/images/login.jpg" onError="alert('Photics.com is not available. Check your Internet connection and try again.')">
OK, so that’s three lines… but that’s just for readability of my reachability code
The trick is with the “onError” command. If the image cannot be loaded, display an error alert. If you’re familiar with web development, you might be twitching right about now. “But… but… onError is not supported by all browser.” It doesn’t matter. The iPhone OS does support it! That’s the beauty of iPhone development. There’s only one browser to support. I admit it, this is not an elegant fix. Yet, there are advantages.
- It’s easy. Only one line of HTML and one image required.
- It does care if you’re using WiFi or 3G.
- You don’t need the Reachability.h or Reachability.m files in your app.
- It doesn’t care if it’s OS version 2.2.1 or 3.1
- It doesn’t give the user an option. It’s only a warning.
- It’s annoying. I hate pop-up alerts.
- Apple may not approve it.