自动发现你的本地开发服务器,即时启用
将你的服务器端 Swift 应用从神秘的汽雾转化为实在的服务器
当您开发一个全栈 Swift 应用程序时,您希望能够轻松地在设备(iPhone、Apple Watch、iPad 等)以及您的开发服务器上测试和调试您的应用程序。如果您正在使用模拟器,那么将您的主机服务器设置为localhost
可能有效,但通常您需要在实际设备上进行测试。
对于服务器和客户端,我们需要一种方式来沟通这些信息,而客户端最初并不知道服务器在哪里。
flowchart TD
%% Nodes for devices with Font Awesome icons
subgraph Devices
iPhone("fa:fa-mobile-alt iPhone")
Watch("fa:fa-square Apple Watch")
iPad("fa:fa-tablet-alt iPad")
VisionPro("fa:fa-vr-cardboard Vision Pro")
end
%% Node for Sublimation service with Font Awesome package icon
Sublimation("fa:fa-box Sublimation")
%% Node for API server with Font Awesome icon
Server("fa:fa-server API Server")
%% Edge connections
Devices <--> Sublimation
Sublimation <--> Server
Apple 平台
Linux
对于较旧的操作系统或 Swift 版本,请查看 主分支和 1.0.0 版本。
仓库 | 描述 |
---|---|
SublimationBonjour | 使用 Bonjour 实现开发服务器自动发现的 Sublimatory 。 |
SublimationNgrok | 使用 Ngrok 和 KVdb 创建公共 URL 并分享它们的 Sublimatory 。 |
SublimationService | 将 Sublimation 用作 生命周期服务 (Lifecycle Service)。 |
SublimationVapor | 将 Sublimation 用作 Vapor 生命周期处理程序 (Lifecycle Handler)。 |
graph TD
A[Which Sublimation Packages to Use] --> B{Need to publicly share URL?}
B -->|Yes| C[Use **SublimationNgrok**]
B -->|No| D[Use **SublimationBonjour**]
C --> E{Which server framework?}
D --> E
E -->|*Vapor*| F[Use **SublimationVapor**]
E -->|*Hummingbird* or other *Lifecycle Service*| G[Use **SublimationService** ]
要使用 Sublimation,你需要选择
例如,如果您正在使用 Bonjour 与 Hummingbird 和一个 iOS 应用,您的包可能如下所示
let package = Package(
...
dependencies: [
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.0.0-alpha.1"),
.package(url: "https://github.com/brightdigit/SublimationBonjour.git", from: "1.0.0"),
.package(url: "https://github.com/brightdigit/SublimationService.git", from: "1.0.0")
],
targets: [
.target(
name: "YouriOSApp",
dependencies: [
.product(name: "SublimationBonjour", package: "SublimationBonjour"),
...
]),
...
.target(
name: "YourServerApp",
dependencies: [
.product(name: "Hummingbird", package: "hummingbird"),
.product(name: "SublimationBonjour", package: "SublimationBonjour"),
.product(name: "SublimationService", package: "SublimationService"),
...
]),
...
]
)
如果您要使用 Vapor 和 Ngrok,它看起来更像是这样
let package = Package(
...
dependencies: [
.package(url: "https://github.com/vapor/vapor.git", from: "4.76.0"),
.package(url: "https://github.com/brightdigit/SublimationNgrok.git", from: "1.0.0"),
.package(url: "https://github.com/brightdigit/SublimationVapor.git", from: "1.0.0")
],
targets: [
.target(
name: "YouriOSApp",
dependencies: [
.product(name: "SublimationKVdb", package: "SublimationNgrok"),
...
]),
...
.target(
name: "YourServerApp",
dependencies: [
.product(name: "Vapor", package: "vapor"),
.product(name: "SublimationNgrok", package: "SublimationNgrok"),
.product(name: "SublimationVapor", package: "SublimationVapor"),
...
]),
...
]
)
请查看包生态系统部分的相应包文档。
要了解更多信息,请查看完整的文档。
此代码在 MIT 许可证下分发。 有关更多信息,请参见 LICENSE 文件。