将Tor和可插件传输集成到您的应用程序中最简单的方法。
此库捆绑了将Tor集成到应用程序中的所有构建块
- Tor.framework,使用
- C-Tor
- GeoIP文件
- 使用
- Lyrebird可插件传输
- Snowflake可插件传输
- 通过Moat/RdSys服务支持自动配置
- 支持自动配置IPv4/IPv6有界网络
- 使用OrbotKit检测和与正在运行的Orbot交互
为了简单轻松地集成,请按如下方式更改您的AppDelegate
import TorManager
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
TorManager.shared.start { error in
print("[\(String(describing: type(of: self)))] error=\(error?.localizedDescription ?? "(nil)")")
}
return true
}
}
extension TorManager {
static let shared = TorManager(
directory: FileManager.default.urls(
for: .cachesDirectory, in: .userDomainMask).first!.appendingPathComponent("tor", isDirectory: true))
}
然后,当您实例化一个WKWebView
时
let webViewConfiguration = WKWebViewConfiguration()
if #available(iOS 17.0, *), let proxy = TorManager.shared.torSocks5Endpoint {
webViewConfiguration.websiteDataStore.proxyConfigurations.removeAll()
webViewConfiguration.websiteDataStore.proxyConfigurations.append(ProxyConfiguration(socksv5Proxy: proxy))
}
let webView = WKWebView(frame: .zero, configuration: webViewConfiguration)
为了配置一个URLSession
let config = URLSessionConfiguration.default
config.connectionProxyDictionary = TorManager.shared.torSocks5ProxyConf
let session = URLSession(configuration: config)
要运行示例项目,首先克隆仓库,然后在示例目录中运行pod install
。
C-Tor将在您的机器上编译,因此您需要准备必要的依赖项
brew install automake autoconf libtool gettext
有关更多详细信息,请参阅Tor.framework README
请将以下内容添加到您的Info.plist
文件中,以便Orbot支持正常工作
<key>LSApplicationQueriesSchemes</key>
<array>
<string>orbot</string>
</array>
TorManager通过CocoaPods提供。要安装它,只需将以下行添加到您的Podfile中
pod 'TorManager'
pod trunk push --allow-warnings
Benjamin Erhart,[email protected] 为 Guardian Project
TorManager可在MIT许可证下使用。有关更多信息,请参阅LICENSE文件。