Reachability and SimplePing much improved and useable on iOS

I will do my best to give everyone credit where credit is due – I have looked at so many websites. 

ReachabilityWithSimplePingMuchImprovedIs your app waiting for the network or an online resource and are you ensuring your users know that there is something going on? If you don’t take care of this or give your users an idea of what the phone is doing – or if it is doing anything – the Apple app store apparently could reject your code and some authors out there… have been rejected and you put at the end of the line to resubmit.

So – the app I am making to load webcams for an in-house preschool security system, that is ONLY supposed to work inside the wifi network. Here is a GREAT resource to start with – you can see if www.apple.com is available. BUT … I wanted to know if the IP address 192.168.1.12 (a local LAN ip address) was available – then I know that it is the correct location. The Apple Reachability example AND a MUCH better one from www.ddg.com have a method called reachabilityWithAddress: but it doesn’t work – it says everything is available with ANY I.P. address! Ideally I want to know if the network IP address of the iphone is the same as that network (see WhatsMyIP) but that is not in my camera app yet.

I upgraded www.ddg.com’s code and converted it to ARC compatible code (refactored it) and modernized it a bit for iOS 6.1.

But the biggest thing, is that I added and wrapped Apple’s SamplePing to it as well – since that gets me over the hump. I have a question into the fellow that made Reachability better to see if he had insight to the native reachabilityWithAddress: .

It also has a method to set how many times it Ping’s since SamplePing never stops and how long to retry those subsequent pings. There is a button next to the ping that allows you  to re-ping. It works when the wifi changes, when cellular changes, when VPN changes – all sorts of new information available with a utility to help you code your own app instead of guessing what might be working or not.

You can edit the ip address live and it resets/retries everything again X times – so in fact it is a useful tool for when you go ‘on the road’ to see what flags etc. and conditions your new app sees. In my case, I need to know if the wifi is live, and if I can ping a certain IP address. Then I can let my users know with an activity indicator, what is going on and why the camera’s do not load – because most of the time they should not load. When your at the customer’s location, the cameras should load. Outside or using cellular 3G/4G or cellular data – it should tell them that things will not work  and how to obtain the guest ID of the customer’s wifi network.

Interesting points and links I used along the way that are not already listed:

  • SimplePing locks the phone for up to a minute if you continuously ping without waiting for a response. Let it time out before you retry AND run that code in a different thread. New concepts exist that we can take advantage of like closures in Groovy.  Here is “Grand Central Dispatch” tutorial #1 and #2 that I used
  • Githib and XCode – I have little hair to spend on this. Spend the $$ and download Tower for Mac. Ahhh – thats better.
  • apple’s sockets and timeouts
  • another good article about reachability that helped me understand

Here is the code on git. Send me a line if you end up re-using it – it is nice to know who and where on the Globe one’s stuff gets to!

3 thoughts on “Reachability and SimplePing much improved and useable on iOS

  1. Pingback: Reachability of IP address? | Unlimitedtricks

  2. Greetings from Darmstadt, Germany
    Thank you for the code sample – I am a newbie to iOS development
    Martin

  3. Pingback: iOS Detect 3G or WiFi – inneka.com

Comments are closed.