How to check internet connection on iOS device?

SniperCoder picture SniperCoder · Jul 31, 2015 · Viewed 42.5k times · Source

I'm wondering how I can check if the user is connect to internet through WIFI or cellular data 3G or 4G.

Also I don't want to check if a website is reachable or not, the thing that I want to check if there is internet on the device or not. I tried to look over the internet all that I see is that they check if the website is reachable or not using the Rechability class.

I want to check if the user has internet or not when he opens my application.

I'm using Xcode6 with Objective-C.

Answer

Jay Bhalani picture Jay Bhalani · Jul 31, 2015

Use this code and import Reachability.h file

if ([[Reachability reachabilityForInternetConnection]currentReachabilityStatus]==NotReachable)
    {
         //connection unavailable
    }
    else
    {
         //connection available
    }