Giter Site home page Giter Site logo

ton-proxy-swift's Introduction

ton-proxy-swift

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
image image

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

  1. Create an application network extension
  2. Create the principal class for your extension
  3. Update .entitlements
import NetworkExtension
import TonutilsProxy

@objc(TunnelProvider)
public final class TunnelProvider: TonproxyTunnelProvider {}
  1. Install the VPN configuration through your main application

Please refer to the sample iOS application for detailed code, if necessary

Using within WKWebView

  1. Configurate WKWebView with TonutilsURLSchemeHandler
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))
  1. Add NSAppTransportSecurity policy to your application's Info.plist
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>
  1. 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

Update pre-built library

You are also free to update the pre-built xssnick/Tonutils-Proxy binaries

./build-artifacts.sh

Authors

ton-proxy-swift's People

Contributors

0xstragner avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

ton-blockchain

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.