Iphone programmatically read proxy settings

I am looking at adding proxy support for my iphone svn client . When you install system vpn in iphone settings, you can add global proxy. Perhaps external applications can read this information via api?

+3
source share
3 answers

Apple has created an example application for this purpose called CFProxySupportTool.

CFProxySupportTool shows how to use the CFProxySupport API to determine if a network connection should go through a proxy; this is useful if you are not using Apple’s high-level network APIs (such as CFNetwork and the URL loading system), but still want to interpret the proxy settings provided by the system.

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

The code is not completely accurate (more than 1000 lines) and is written in simple C. You can also see the source code of the startRequest ASIHTTPRequest function, which seems to be based on CFProxySupportTool.

Here begins:

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

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

if (!proxies.count)
  return;

firstProxySettings = [proxies objectAtIndex:0];

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

    script = [NSString stringWithContentsOfURL:pacScriptURL
                                  usedEncoding:NULL
                                         error:&nsError];

    if (nsError)
      return;

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

    if (cfErrorRef || !proxies.count)
      return;

    firstProxySettings = [proxies objectAtIndex:0];
  }

/* Now use `firstProxySettings' */
+5
source

- ASIHttpRequest, . .

, .

0

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

0
source

Source: https://habr.com/ru/post/1720626/


All Articles