額译柏,最近公司的接口讓人給通過抓包給破解了挑豌,搞不清楚https的證書是怎么泄露的酗失,然后就有了這么個需求义钉,只要是網(wǎng)絡設置了代理,那么就禁止一切網(wǎng)絡訪問规肴,這里記錄一下如何判斷是否設置了代理捶闸。
需要導入框架CFNetwork
然后,這個方法是mrc的:需要添加-fno-objc-arc的flag
代碼如下:
+ (BOOL)getProxyStatus {
NSDictionary *proxySettings = NSMakeCollectable([(NSDictionary *)CFNetworkCopySystemProxySettings() autorelease]);
NSArray *proxies = NSMakeCollectable([(NSArray *)CFNetworkCopyProxiesForURL((CFURLRef)[NSURL URLWithString:@"http://www.google.com"], (CFDictionaryRef)proxySettings) autorelease]);
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;
}
}