iOS 判断设备网络是否使用代理
– (BOOL)getProxyStatus {
NSDictionary *proxySettings = (__bridge NSDictionary *)(CFNetworkCopySystemProxySettings());
NSArray *proxies = (__bridge NSArray *)(CFNetworkCopyProxiesForURL((__bridge CFURLRef _Nonnull)([NSURL URLWithString:@”http://www.baidu.com”]), (__bridge CFDictionaryRef _Nonnull)(proxySettings)));
NSDictionary *settings = [proxies objectAtIndex:0];
NSLog(@”host=%@”, [settings objectForKey:(NSString *)kCFProxyHostNameKey]);
NSLog(@”port=%@”, [settings objectForKey:(NSString *)kCFProxyPortNumberKey]);
NSLog(@”type=%@”, [settings objectForKey:(NSString *)kCFProxyTypeKey]);
if ([[settings objectForKey:(NSString *)kCFProxyTypeKey] isEqualToString:@”kCFProxyTypeNone”]){
//没有设置代理
return NO;
}else{
//设置代理了
return YES;
}
}
Android 判断设备网络是否使用代理
/*
* 判断设备 是否使用代理上网
* */
private boolean isWifiProxy(Context context) {
final boolean IS_ICS_OR_LATER = Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH;
String proxyAddress;
int proxyPort;
if (IS_ICS_OR_LATER) {
proxyAddress = System.getProperty(“http.proxyHost”);
String portStr = System.getProperty(“http.proxyPort”);
proxyPort = Integer.parseInt((portStr != null ? portStr : “-1”));
} else {
proxyAddress = android.net.Proxy.getHost(context);
proxyPort = android.net.Proxy.getPort(context);
}
return (!TextUtils.isEmpty(proxyAddress)) && (proxyPort != -1);
}
原创文章如转载请注明: