美文网首页
iOS 监测是否设置网络代理

iOS 监测是否设置网络代理

作者: 见惯不怪 | 来源:发表于2018-03-27 16:03 被阅读16次
    工作备忘
    + (BOOL)getProxyStatusURL:(NSURL *)url {
        
        NSDictionary *proxySettings = (__bridge NSDictionary *)(CFNetworkCopySystemProxySettings());
        NSArray *proxies = (__bridge NSArray *)(CFNetworkCopyProxiesForURL((__bridge CFURLRef _Nonnull)(url), (__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 NO;
        }
        else
        {
            NSLog(@"设置了代理");
            return YES;
        }
    }
    

    相关文章

      网友评论

          本文标题:iOS 监测是否设置网络代理

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