wolverine
wolverine

Reputation: 309

How to bypass proxy in iOS programmatically?

These are my steps

Network is available now for the Wifi.

Open system WiFi settings

Select manual proxy settings

Configure invalid parameters

Open browser and make sure that internet is not available

Start the app and make sure there is no internet

Is there any way that programmatically from inside the app, I can bypass those proxy settings so that I can connect to the internet?

Upvotes: 2

Views: 4757

Answers (2)

Edison Lo
Edison Lo

Reputation: 476

Encounter your problem in 2018, after some time digging in the document found the key kCFStreamPropertyProxyLocalBypass for setting in the proxy dictionary. fyi:https://developer.apple.com/documentation/cfnetwork/kcfstreampropertyproxylocalbypass

Objective-C

NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration];

NSDictionary *proxyDict = @{
                        @"HTTPEnable"  : [NSNumber numberWithInt:1],
                        (NSString *)kCFStreamPropertyProxyLocalBypass  : @"10.26.*.*",              
                        @"HTTPSEnable" : [NSNumber numberWithInt:1],
                       (NSString *)kCFStreamPropertyProxyLocalBypass  : @"10.26.*.*"
                          };
sessionConfig.connectionProxyDictionary = proxyDict;

Swift

let sessionConfig = URLSessionConfiguration.default
var proxyDict = [AnyHashable : Any]()
proxyDict[kCFStreamPropertyProxyLocalBypass as String] = "10.26.*.*"
sessionConfig.connectionProxyDictionary = proxyDict
let session = URLSession.init(configuration: config, delegate: nil, delegateQueue: OperationQueue.current)

Upvotes: 1

ykay
ykay

Reputation: 1973

You probably want to use CFHTTPStream, which by default does not automatically use the proxy settings.

For more information, read the CFNetwork Programming Guide.

Upvotes: 0

Related Questions