let dic = CFNetworkCopySystemProxySettings()!.takeUnretainedValue()
let arr = CFNetworkCopyProxiesForURL(URL(string: "https://www.baidu.com")! as CFURL, dic).takeUnretainedValue()
let obj = (arr as [AnyObject])[0]
let host = obj.object(forKey: kCFProxyHostNameKey) ?? "null"
let port = obj.object(forKey: kCFProxyPortNumberKey) ?? "null"
let type = obj.object(forKey: kCFProxyTypeKey) ?? "null"
print(host)
print(port)
print(type)
if obj.object(forKey: kCFProxyTypeKey) == kCFProxyTypeNone {
print("没有设置代理")
let alert = UIAlertController(title: "代理检测", message: "没有设置代理", preferredStyle: .alert)
present(alert, animated: true, completion: nil)
}else {
print("设置代理了")
let alert = UIAlertController(title: "代理检测", message: "设置代理了\n\(host)\n\(port)\n\(type)", preferredStyle: .alert)
present(alert, animated: true, completion: nil)
}
网友评论