1

I'm looking to create an iOS app that implements a standard Safari-like web browser which proxies all of its traffic through a proxy server. Specifically, it must use its own a proxy configuration so that only its traffic is directed through the proxy, as opposed to using iOS's system settings.

I have some flexibility with what kind of proxy is used. I'd prefer a Socks5 proxy, but an HTTP / HTTPS proxy is okay too. Either way, it must support authentication.

I'd strongly prefer to use SFSafariViewController, as I'd like this web browser to be as close to the experience of using Safari as possible, but I understand that SFSafariViewController is limited and that may not be possible. Failing that, I'd hope to use WKWebView, but if that's not possible either, I can reluctantly fall back on UIWebView.

How would one go about accomplishing this?

edit: I should add that I'm not planning on releasing this app on the app store, so I'm open to methods that normally wouldn't fly there, like undocumented APIs and swizzling. All else being equal though I'd prefer to not utilize methods like that.

Bri Bri
  • 2,169
  • 3
  • 19
  • 44

1 Answers1

0

You can implement a local web server, hosted at localhost:<some_weird_port_number>, and make your WKWebView load only local addresses from that server. Your server will load what you want and how you want, and then will give it as a response to a web view.

Eugene Dudnyk
  • 5,553
  • 1
  • 23
  • 48
  • I don't quite see how I could use that to allow for normal web browsing. Once a page is loaded and then provided by the local web server, any links to the page's resources or to other pages will not use a localhost address. – Bri Bri Mar 29 '17 at 18:45
  • Yes, you would have to crawl web page content and replace url links there. Other approach can be that you will use UIWebView and custom NSURLProtocol to completely override network connectivity. – Eugene Dudnyk Mar 29 '17 at 20:26
  • I do want to avoid crawling web pages, especially because that would mean I would *also* have to replace url links in scripts, which is a dicey and probably impossible task. Thanks for the tip on NSURLProtocol and UIWebView though. I have been looking into that. Unfortunately UIWebView means using the less performant javascript engine and having to reinvent the wheel in terms of UI in order to provide a Safari-like experience. – Bri Bri Mar 29 '17 at 20:30
  • Yep, unfortunately, WKWebView (which is also used in SFSafariViewController) is running web connectivity in a separate process, and there is no possibility to override anything. – Eugene Dudnyk Mar 29 '17 at 20:33
  • I was considering trying method swizzling, so thanks for letting me know it wouldn't work in advance! – Bri Bri Mar 29 '17 at 20:35
  • Swizzling can work with WKWebView though, depending on what you want to swizzle. For example, I was able to swizzle content view of WKWebView and deal with its buggy gesture recognition. WebKit2 and WKWebView is opensource, you can check out the code and find what you want to swizzle there. Hope that your app is not for app store :) – Eugene Dudnyk Mar 29 '17 at 20:38
  • Nope, not for the app store! I was thinking of swizzling something that gives me access to an NSURLSession or NSURLSessionConfiguration, and then overriding its behavior so that it always uses a proxy, but that's probably happening in a different process and therefore not something I can swizzle. But I didn't realize WKWebView is open source so I may tinker with it and see what I can manage. – Bri Bri Mar 29 '17 at 20:53