iOS和Android判断设备网络是否使用代理

 

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);

}

 

标签:
分类:
iOS开发 | 发布:inzaghi | 评论:iOS和Android判断设备网络是否使用代理已关闭评论 | 发表时间:2020-08-6 18:16
引用:点击这里获取该日志的TrackBack引用地址
上一篇:
下一篇:

Comments are closed.

Design By Inzaghi | 京ICP备16047555号-1