ton-proxy-swift
July 17, 2023 ยท View on GitHub
A Swift wrapper for the xssnick/Tonutils-Proxy v1.3.0 library.
Supported platforms
- iOS / iPadOS / macOS (Designated for iPad)
NOTE: Simulators are not supported.
Screenshots
| Safari (NetworkExtension) | WKWebView |
|---|---|
Installation
.package(
url: "https://github.com/0xstragner/ton-proxy-swift.git",
.upToNextMajor(from: "0.3.0")
)
Usage examples
Start from strach
import TonutilsProxy
let tunnel = TonutilsProxy.shared
try await tunnel.start(9090)
try await tunnel.stop()
Using within NetworkExtension
- 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
Using within WKWebView
- Configurate
WKWebViewwithTonutilsURLSchemeHandler
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
NSAppTransportSecuritypolicy to your application'sInfo.plist
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
CMD+R
:warning: 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
Update pre-built library
You are also free to update the pre-built xssnick/Tonutils-Proxy binaries
./build-artifacts.sh
Authors
- adam@stragner.com / stragner.ton