Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Check if iOS app is connected to proxy
func isConnectedToProxy() -> Bool {
let host = "http://www.example.com"
if let url = URL(string: host),
let proxySettingsUnmanaged = CFNetworkCopySystemProxySettings() {
let proxySettings = proxySettingsUnmanaged.takeRetainedValue()
let proxyUnmanaged = CFNetworkCopyProxiesForURL(url as CFURL, proxySettings)
if let proxies = proxyUnmanaged.takeRetainedValue() as? [[String : AnyObject]], proxies.count > 0 {
let proxy = proxies[0]
let key = kCFProxyTypeKey as String
let value = kCFProxyTypeNone as String
if let v = proxy[key] as? String, v != value {
return true
}
}
}
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment