美文网首页OC-开发案例收集很常
iOS判断是否开启代理,防止Charles抓包

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

作者: All_Be_Alright | 来源:发表于2021-04-13 17:19 被阅读0次

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

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

          }

    }

    相关文章

      网友评论

        本文标题:iOS判断是否开启代理,防止Charles抓包

        本文链接:https://www.haomeiwen.com/subject/nryclltx.html