XrayKit is a robust iOS framework that provides a native integration of Xray-core functionality for iOS applications. This framework serves as a high-performance wrapper around the Xray-core, enabling seamless implementation and management of Xray features in iOS applications.
XrayKit delivers a comprehensive suite of APIs for interacting with Xray-core, encompassing configuration management, geo data handling, connection testing, and runtime control. The framework is engineered to maintain the full power of Xray-core while providing a developer-friendly interface.
I offer professional development services for custom iOS VPN and proxy client applications. Whether you need a complete solution from scratch or integration with existing systems, I can help bring your vision to life. My expertise includes:
- Custom VPN client development
- Proxy client implementation
- Network security solutions
- iOS app architecture
- Performance optimization
- Security hardening
For professional inquiries, please contact me on Telegram: @codewithtamim
- In Xcode, select File > Add Packages...
- Enter the repository URL:
https://github.com/CodeWithTamim/XrayKit.git
- Select the version you want to use
- Click Add Package
- Download the latest release from the Releases page
- Drag the
XrayKit.xcframework
into your project - Ensure "Copy items if needed" is checked
- Add the framework to your target's "Frameworks, Libraries, and Embedded Content" section
/// Creates a properly formatted base64 request for running Xray
/// - Parameter configStr: The Xray configuration string
/// - Returns: A base64 encoded request string
func NewXrayRunRequest(configStr: String) -> String
/// Starts Xray with the provided configuration
/// - Parameter xrayRequest: Base64 encoded request string
/// - Returns: Base64 encoded response string
func RunXray(xrayRequest: String) -> String
/// Stops the running Xray instance
/// - Returns: Base64 encoded response string
func StopXray() -> String
/// Retrieves the current Xray version
/// - Returns: Base64 encoded version string
func XrayVersion() -> String
/// Tests the Xray configuration
/// - Parameter base64Text: Base64 encoded configuration test request
/// - Returns: Base64 encoded test results
func TestXray(base64Text: String) -> String
/// Performs a ping test for outbound connection
/// - Parameter base64Text: Base64 encoded ping request containing:
/// - datDir: String
/// - configPath: String
/// - timeout: Int
/// - url: String
/// - proxy: String
/// - Returns: Base64 encoded ping results
func Ping(base64Text: String) -> String
/// Counts geo data entries
/// - Parameter base64Text: Base64 encoded request containing:
/// - datDir: String
/// - name: String
/// - geoType: String
/// - Returns: Base64 encoded count results
func CountGeoData(base64Text: String) -> String
/// Thins geo data based on configuration
/// - Parameter base64Text: Base64 encoded request containing:
/// - datDir: String
/// - configPath: String
/// - dstDir: String
/// - Returns: Base64 encoded operation results
func ThinGeoData(base64Text: String) -> String
/// Reads geo files
/// - Parameter base64Text: Base64 encoded request
/// - Returns: Base64 encoded JSON containing domain and IP arrays
func ReadGeoFiles(base64Text: String) -> String
/// Queries inbound and outbound statistics
/// - Parameter base64Text: Base64 encoded server string
/// - Returns: Base64 encoded statistics
func QueryStats(base64Text: String) -> String
import XrayKit
// Xray configuration
let config = """
{
"inbounds": [
{
"port": 1080,
"protocol": "socks",
"settings": {
"auth": "noauth"
}
}
],
"outbounds": [
{
"protocol": "freedom"
}
]
}
"""
// Create base64 request
let base64Request = XrayKit.NewXrayRunRequest(configStr: config)
// Initialize Xray
let response = XrayKit.RunXray(xrayRequest: base64Request)
// Ping configuration
let pingConfig = """
{
"datDir": "/path/to/dat",
"configPath": "/path/to/config.json",
"timeout": 5000,
"url": "https://www.google.com",
"proxy": "your-proxy"
}
"""
let pingData = pingConfig.data(using: .utf8)!
let base64Ping = pingData.base64EncodedString()
let response = XrayKit.Ping(base64Text: base64Ping)
// Geo data configuration
let geoConfig = """
{
"datDir": "/path/to/dat",
"name": "geoip",
"geoType": "ip"
}
"""
let geoData = geoConfig.data(using: .utf8)!
let base64Geo = geoData.base64EncodedString()
let response = XrayKit.CountGeoData(base64Text: base64Geo)
All API responses are returned as base64 encoded strings. The following example demonstrates proper response handling:
if let responseData = Data(base64Encoded: response),
let jsonString = String(data: responseData, encoding: .utf8) {
if let jsonData = jsonString.data(using: .utf8),
let json = try? JSONSerialization.jsonObject(with: jsonData) as? [String: Any] {
// Process the decoded response
print(json)
}
}
The framework maintains the following directory structure:
.
├── dat/ # Geo data files directory
└── config/ # Configuration files directory
└── config.json # Xray configuration file
- iOS 15.0+
- Latest Xcode version recommended
- Swift 5.0+
CodeWithTamim
This project is licensed under the MIT License - see the LICENSE file for details.
We welcome contributions to XrayKit. Please follow these guidelines when contributing:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- Follow Swift style guidelines
- Write unit tests for new features
- Update documentation for API changes
- Ensure all tests pass before submitting PR
- Use meaningful commit messages
- Be respectful and inclusive
- Be patient and welcoming
- Be thoughtful
- Be collaborative
- When disagreeing, try to understand why
Please report bugs and feature requests using the GitHub issue tracker. Include:
- Detailed description of the issue
- Steps to reproduce
- Expected behavior
- Actual behavior
- Environment details