A Swift wrapper for the xssnick/Tonutils-Proxy v1.3.0 library.
- iOS / iPadOS / macOS (Designated for iPad)
NOTE: Simulators are not supported.
Safari (NetworkExtension) | WKWebView |
---|---|
.package(
url: "https://github.com/0xstragner/ton-proxy-swift.git",
.upToNextMajor(from: "0.3.0")
)
import TonutilsProxy
let tunnel = TonutilsProxy.shared
try await tunnel.start(9090)
try await tunnel.stop()
- Create an application network extension
- Create the principal class for your extension
- Update
.entitlements
import NetworkExtension
import TonutilsProxy
@objc(TunnelProvider)
public final class TunnelProvider: TonproxyTunnelProvider {}
- Install the VPN configuration through your main application
Please refer to the sample iOS application for detailed code, if necessary
- Configurate
WKWebView
withTonutilsURLSchemeHandler
import TonutilsProxy
import WebKit
guard let url = URL(string: "http://foundation.ton")
else {
return
}
let port = UInt16(1234)
let tunnel = TonutilsProxy.shared
// Start proxy server
let parameters = try await tunnel.start(port)
// Create `WKURLSchemeHandler``
let schemeHandler = TonutilsURLSchemeHandler(
address: parameters.host,
port: parameters.port
)
// Creeate `WKWebView`` with `WKWebViewConfiguration`
let configuration = WKWebViewConfiguration()
configuration.setURLSchemeHandler(schemeHandler)
let webView = WKWebView(frame: view.bounds, configuration: configuration)
webView.load(.init(url: url))
- Add
NSAppTransportSecurity
policy to your application'sInfo.plist
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
CMD+R
⚠️ Since Apple restricts the use of proxies inside WKWebView in a legal way, I have implemented a small workaround (hack) for it
Please refer to the sample iOS application for detailed code, if necessary
You are also free to update the pre-built xssnick/Tonutils-Proxy binaries
./build-artifacts.sh
- adam@stragner.com / stragner.ton