OC-开发案例收集很常

iOS判断是否开启代理,防止Charles抓包

2021-04-13  本文已影响0人  All_Be_Alright

直接检查是否设置了代理即可

- (BOOL)checkProxySetting

{

      NSDictionary*proxySettings = (__bridgeNSDictionary*)  (CFNetworkCopySystemProxySettings());

      NSArray*proxies = (__bridgeNSArray*)(CFNetworkCopyProxiesForURL((__bridgeCFURLRef_Nonnull)([NSURLURLWithString:@"https://www.baidu.com"]), (__bridgeCFDictionaryRef_Nonnull)(proxySettings)));

      NSLog(@"\n%@",proxies);

      NSDictionary*settings = proxies[0];

      NSLog(@"%@",[settings objectForKey:(NSString *)kCFProxyHostNameKey]);

      NSLog(@"%@",[settings objectForKey:(NSString *)kCFProxyPortNumberKey]);

      NSLog(@"%@",[settings objectForKey:(NSString *)kCFProxyTypeKey]);

      if([[settingsobjectForKey:(NSString*)kCFProxyTypeKey]isEqualToString:@"kCFProxyTypeNone"])

      {

          NSLog(@"没设置代理");

          returnNO;

      }

      else

      {

          NSLog(@"设置了代理");

          returnYES;

      }

}

上一篇 下一篇

猜你喜欢

热点阅读