AHProxySettings *settings = [[AHProxySettings alloc] init];
NSLog(@"%@",settings.HTTPProxy.exportString);
NSLog(@"%@",settings.HTTPSProxy.exportString);
NSLog(@"%@",settings.FTProxy.exportString);
NSLog(@"%@",settings.SOCKSProxy.exportString);
NSLog(@"%@",settings.autoDetectedProxies);
// By default HTTP(S) and FTP proxy objects will be
// populated with a proxy returned from a .PAC / WPAD request.
// To disable this behavior
settings.useAutoDetectAsFailover = NO;
但是启动此项目的目的是将系统代理值放入 NSTask 中,因此还有一个类别。
#import "NSTask+useSystemProxies.h"
NSTask *task = [NSTask alloc] init];
task.launchPath = @"/usr/bin/curl"
task.arguments = @[ @"-k", _testURL.stringValue ];
[task useSystemProxies];
// This is equivalent to
// export HTTP_PROXY = ...
// export HTTPS_PROXY = ...
// export FTP_PROXY = ...
// export NO_PROXY = ...
// based on your system settings
// or to dynamically determine if a proxy
// is needed based on a PAC file
[task useSystemProxiesForDestination:@"github.com"];
[task launch];
// ... then do what you will with the results ... //
如果不在 CocoaPods 中使用,请确保在构建设置的其它链接器标志中包含 -ObjC
,以便类别不会被优化掉。