我爱编程

ios 方抓包检测代理arc方法

2018-05-28  本文已影响17人  ClementGu

之前找的资料都是mrc的现在给大家分享下arc的方法,亲测有效。

1.导入CFNetWork框架

#import <CFNetwork/CFNetwork.h>


2.复制以下代码

/** 判断是否设置代理 */

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

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

NSDictionary *settings = proxies[0];    

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

    if ([[settings objectForKey:(NSString *)kCFProxyTypeKey] isEqualToString:@"kCFProxyTypeNone"])     {    

    NSLog(@"没代理");

        return YES;  

  }     else     {        

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

      return NO;  

  }

}


3.完成 

上一篇下一篇

猜你喜欢

热点阅读