title: Check internet availability even if device is connected to Wifi or mobileData
body: <p>How can, I check internet connectivity.?</p>
  
  <p>The below code just shows the connection to wifi or mobile network but cannot check current internet connectivity.</p>
  
  <pre><code>class func isConnectedToNetwork() -&gt; Bool {
  
      var zeroAddress = sockaddr_in()
      zeroAddress.sin_len = UInt8(MemoryLayout&lt;sockaddr_in&gt;.size)
      zeroAddress.sin_family = sa_family_t(AF_INET)
  
      guard let defaultRouteReachability = withUnsafePointer(to: &amp;zeroAddress, {
          $0.withMemoryRebound(to: sockaddr.self, capacity: 1) {
              SCNetworkReachabilityCreateWithAddress(nil, $0)
          }
      }) else {
          return false
      }
  
      var flags: SCNetworkReachabilityFlags = []
      if !SCNetworkReachabilityGetFlags(defaultRouteReachability, &amp;flags) {
          return false
      }
  
      let isReachable = flags.contains(.reachable)
      let needsConnection = flags.contains(.connectionRequired)
  
      return (isReachable &amp;&amp; !needsConnection)
  }
  </code></pre>