How to check if WiFi is on or off in iOS Swift 2?

I want to check if the wifi is off then show alert to the user to check his/her connectivity.

I find code like this but it checks if there is an internet connection, not checking if the wifi is on or off:

  • UIDocument openWithCompletionHandler: crash
  • How to figure out when a HTML5 video player enters the full screen mode on iOS / iPads?
  • Detect touch on child node of object in SpriteKit
  • Custom init for UIViewController in Swift with interface setup in storyboard
  • Iphone localStorage “QUOTA_EXCEEDED_ERR” issue
  • Importing and querying through an SQLite database in Swift - iOS
  • func isConnectionAvailble()->Bool{
      var rechability = SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, "").takeRetainedValue()
      var flags : SCNetworkReachabilityFlags = 0
      if SCNetworkReachabilityGetFlags(rechability, &flags) == 0
         return false
      let isReachable = (flags & UInt32(kSCNetworkFlagsReachable)) != 0
      let needsConnection = (flags & UInt32(kSCNetworkFlagsConnectionRequired)) != 0
      return (isReachable && !needsConnection)

    3 Solutions Collect From Internet About “How to check if WiFi is on or off in iOS Swift 2?”

    You can’t.

    With reachability, you can distinguish three things: a. You have a WiFi connection, you may or may not have a mobile data connection. b. You have a mobile data connection, but no WiFi connection. c. You have neither WiFi nor mobile data connection.

    You can’t check whether WiFi is turned off, or whether WiFi is turned off but there is no WiFi network nearby, or whether Airplane mode has been turned on.

    For mobile data, you can use the telephony class to find whether your device is capable of mobile data connections (iPhone and not iPad, and SIM card plugged in), and you can detect whether mobile data is disabled in the preferences of your application.

    You can take a look at the official Apple sample for Reachability:

    var netStatus = reachability.currentReachabilityStatus()
    var connectionRequired = reachability.connectionRequired()
    var statusString = ""
    switch netStatus {
        case NotReachable:
        case ReachableViaWWAN:
        case ReachableViaWiFi:


    You can use this method to check:

    First you import this framework:

    import SystemConfiguration.CaptiveNetwork
    func isWifiEnabled() -> Bool {
            var hasWiFiNetwork: Bool = false
            let interfaces: NSArray = CFBridgingRetain(CNCopySupportedInterfaces()) as! NSArray
            for interface  in interfaces {
               // let networkInfo = (CFBridgingRetain(CNCopyCurrentNetworkInfo(((interface) as! CFString))) as! NSDictionary)
                let networkInfo: [AnyHashable: Any]? = CFBridgingRetain(CNCopyCurrentNetworkInfo(((interface) as! CFString))) as? [AnyHashable : Any]
                if (networkInfo != nil) {
                    hasWiFiNetwork = true
            return hasWiFiNetwork;