Take the 2-minute tour ×

I'm looking at adding proxy support to my iphone svn client. When you set up a system wide vpn in the iphone settings you can add a global proxy. Is it possible for external apps to read this information through the api?

share|improve this question

3 Answers 3

Apple has created a sample application for this purpose, called CFProxySupportTool.

CFProxySupportTool shows how to use the CFProxySupport APIs to determine whether a network connection should pass through a proxy; this is useful if you're not using Apple's high-level networking APIs (like CFNetwork and the Foundation URL loading system) but still want to interpret the system-supplied proxy settings.

It's currently available at https://developer.apple.com/library/mac/#samplecode/CFProxySupportTool/Introduction/Intro.html

The code isn't exactly terse (more than 1000 lines), and is written in plain C. You can also look at the source code of ASIHTTPRequest's startRequest function, which seems to be based on CFProxySupportTool.

Here's a start:

systemProxySettings = [(NSDictionary *) CFNetworkCopySystemProxySettings() autorelease];

proxies = [(NSArray *) CFNetworkCopyProxiesForURL((CFURLRef) URL, (CFDictionaryRef) systemProxySettings) autorelease];

if (!proxies.count)

firstProxySettings = [proxies objectAtIndex:0];

if (nil != (pacScriptURL = [firstProxySettings objectForKey:(NSString *)kCFProxyAutoConfigurationURLKey]))
    CFErrorRef cfErrorRef = NULL;
    NSError *nsError = nil;
    NSString *script;

    script = [NSString stringWithContentsOfURL:pacScriptURL

    if (nsError)

    proxies = [(NSArray *) CFNetworkCopyProxiesForAutoConfigurationScript((CFStringRef) script, (CFURLRef) URL, &cfErrorRef) autorelease];

    if (cfErrorRef || !proxies.count)

    firstProxySettings = [proxies objectAtIndex:0];

/* Now use `firstProxySettings' */
share|improve this answer

Have you investigated using something like ASIHttpRequest, see the section in the how to document describing proxy support.

At the very least the source code should contain some helpful guidance.

share|improve this answer

Take a look at the CFProxySupport API, in particular CFNetworkCopyProxiesForURL() will let you read the proxies that are needed to get to a particular URL.

share|improve this answer

Your Answer


