So as you no doubt know if you’ve been reading us for a while, your iPhone programs need to go figure out for themselves the status of the network connection before using it in any way if they don’t want to be rejected, and the Reachability sample is … well, 2.0 is better than it was, let’s leave it there. (There’s a good post on its use here too.)
But ho! Here’s a fellow who’s taken it on himself to do something about it with a refactored/extended Reachability and extensive documentation:
… While the 2.0 version of this code is much better than v1.5, it is still quite raw. (For example, there is a bare [super init]; in a class method [line 175 in Reachability.m]. It does nothing. It also has two routines with misspellings in their names: -startNotifer/-stopNotifer should be -startNotifier/-stopNotifier) To me, these are signs of raw code. To remedy this, I have significantly reengineered this class.
I had three goals when starting this process. First, I wanted to understand how to use this code. It isn’t at all apparent how these routines should be used. What order should they be called in and what do the various tests and values mean? Second, my scan of the code convinced me that it was written by a low level network engineer. They had made implementation decisions that were not terribly friendly to using it in a Cocoa Touch program. I wanted a class that fit in with my coding style. Third, because the core network testing routine -networkStatusForFlags: was not, in my opinion, clear, I did not feel comfortable shipping it in my app, weLost™. I wanted to have confidence in this code…
We love that kind of people. At writing his latest (BSD-licensed) version, with the Apple original, is at Reachability 2.0.4ddg.zip. Enjoy!
h/t: iPhoneSDK!
UPDATE:
Check out the block-based NPReachability too!
Continue Reading →JAN