title: Check whether device is connected to a VPN in iOS 12
body: <p>I am using the code below (Swift 3 and Swift 4 compatible) to check the VPN connection on iOS devices which is not working in iOS 12 and above. How can I check the vpn connectivity in iOS 12</p>
  
  <pre><code>func isVPNConnected() -&gt; Bool {
      let cfDict = CFNetworkCopySystemProxySettings()
      let nsDict = cfDict!.takeRetainedValue() as NSDictionary
      let keys = nsDict["__SCOPED__"] as! NSDictionary
  
      for key: String in keys.allKeys as! [String] {
          if (key == "tap" || key == "tun" || key == "ppp" || key == "ipsec" || key == "ipsec0") {
              return true
          }
      }
      return false
  }
  </code></pre>
  
  <p>Thank you for your help.</p>