Created
April 24, 2018 13:44
-
-
Save azwan082/7dbaf881819b973099ae9afbe6f544ec to your computer and use it in GitHub Desktop.
Check if iOS app is connected to proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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