The universal proxy platform.
https://community.sagernet.org/c/sing-box/
Copyright (C) 2022 by nekohasekai <contact-sagernet@sekai.icu>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
In addition, no derivative work may use the name or imply association
with this application without prior consent.
启动 singbox
要启动 singbox,您需要创建一个 LibboxBoxService 实例,并调用其 start() 方法。在启动之前,可以通过构造函数传入配置参数来初始化服务。
示例代码
do {
// 假设 configContent 是您的配置参数
let configContent: String = "您的配置参数"
let platformInterface: LibboxPlatformInterfaceProtocol? = nil // 根据需要设置平台接口
guard let sinboxService = LibboxNewService(configContent, platformInterface, nil) else {
print("初始化 sinbox 服务失败")
return
}
try sinboxService.start()
print("sinbox 服务已启动")
} catch {
print("启动 sinbox 服务时出错: \(error)")
}
停止 singbox
要停止 singbox,您需要调用 LibboxBoxService 实例的 close() 方法。
示例代码
do {
// 假设 sinboxService 是已启动的 LibboxBoxService 实例
try sinboxService.close()
print("sinbox 服务已停止")
} catch {
print("停止 sinbox 服务时出错: \(error)")
}
重载 singbox 重载 singbox 通常意味着使用新的配置参数重新启动服务。这可以通过先关闭当前服务,再使用新的配置参数启动服务来实现。
示例代码
do {
// 假设 sinboxService 是已启动的 LibboxBoxService 实例
// 停止当前服务
try sinboxService.close()
// 使用新的配置参数重新初始化和启动服务
let newConfigContent: String = "新的配置参数"
let newPlatformInterface: LibboxPlatformInterfaceProtocol? = nil // 根据需要设置新的平台接口
guard let newSinboxService = LibboxNewService(newConfigContent, newPlatformInterface, nil) else {
print("重新初始化 sinbox 服务失败")
return
}
try newSinboxService.start()
print("sinbox 服务已使用新配置重载")
} catch {
print("重载 sinbox 服务时出错: \(error)")
}
请注意,具体的配置参数 configContent 应该根据您的实际需求和 singbox 的配置文档来设置。这些示例代码仅展示了如何通过 API 接口启动、停止和重载服务,实际使用时需要根据您的具体场景进行调整。