Search code examples
iosobjective-ccocoa-touchreachability

How to check internet connection on iOS device?


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.


Solution

  • Use this code and import Reachability.h file

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