测试已测试 | ✗ |
Lang语言 | SwiftSwift |
许可证 | MIT |
发布上次发布 | 2017 年 8 月 |
SwiftSwift 版本 | 3.1 |
SPM支持 SPM | ✓ |
由 Spreadbot 维护。
依赖关系 | |
Alamofire | ~> 4.5 |
Starscream | ~> 2.1 |
iOS 客户端的应用
要将 Spreadbot_iOS 作为 Swift 包管理器 包使用,只需将以下内容添加到您的 Package.swift 文件中。
import PackageDescription
let package = Package(
name: "HelloSpreadbot_iOS",
dependencies: [
.Package(url: "https://github.com/Spreadbot/Spreadbot_iOS.git", "1.0.9")
]
)
如果您不愿使用上述任何依赖管理器,可以将 Spreadbot_iOS 手动集成到项目中。
cd
命令进入您的顶级项目目录,并运行以下命令,如果您的项目尚未初始化为 git 仓库$ git init
$ git submodule add https://github.com/Spreadbot/Spreadbot_iOS.git
$ git submodule update --init --recursive
打开新的 Spreadbot_iOS
文件夹,并将 Spreadbot_iOS.xcodeproj
拖动到 Xcode 项目导航器中的应用程序 Xcode 项目中。
它应该位于您的应用程序蓝色项目图标下的嵌套位置。它是在所有其他 Xcode 组之上还是之下并不重要。
在项目导航器中选择 Spreadbot_iOS.xcodeproj
并验证部署目标与您的应用程序目标一致。
接下来,在项目导航器中选择您的应用程序项目(蓝色项目图标),以导航到目标配置窗口,并在侧边栏的“Targets”下选择应用程序目标。
在该窗口的上端选项卡栏中,打开“General”面板。
在“Embedded Binaries”部分下单击 +
按钮。
您将看到两个不同的 Spreadbot_iOS.xcodeproj
文件夹,每个文件夹内部都有一个嵌套在“Products”文件夹中的不同版本的 Spreadbot_iOS.framework
。
您可以从“Products”文件夹中选择任意一个。
选择 Spreadbot_iOS.framework
。
就这样!
Spreadbot_iOS.framework
会在复制文件构建阶段自动添加为目标依赖、链接框架和嵌入式框架,这是在模拟器和设备上构建所必需的。
+
按钮。Spreadbot_iOS.framework
添加。// Import
import Spreadbot_iOS
// Setup and configuration
let spreadbot: Spreadbot = Spreadbot(config: [
"baseURL": "http://wwww.my-spreadbot-server.com",
"authURL": "http://wwww.my-spreadbot-auth-server.com",
"accessToken": "myAccessToken",
"refreshToken": "myRefreshToken",
"base64Credentials": "MyBase64Credentials",
"log": true // should be false in production
])
// Connect and subscribe to a path
spreadbot.establishConnection(path: "myPath")
spreadbot.onOpen {
// When a connection has been opened
}
spreadbot.onError { (error) in
// When a connection error has occured
}
spreadbot.onMessage { (id, event, data) in
// id: iteration
// event: path
// data: data
}
// Send string message
spreadbot.sendMessageString(message: "myMessage")
// Send binary message
spreadbot.sendMessageBinary(message: data)
// Disconnect
spreadbot.closeConnection()
如果 WebSocket 连接无法建立,则使用服务器端事件 (SSE) 作为后备。
如果 SSE 连接无法建立,则尝试 HTTP 长轮询,每 15 秒轮询一次新数据。
如果 WebSocket 连接无法建立,则尝试通过 POST 请求发送数据。在没有互联网连接的情况下,最多可以排队 100 个请求。
所有连接类型在意外网络断开的情况下都会尝试重新连接最多 3 次。
如果由于网络不可达而断开连接,则 Spreadbot 库将等待网络再次变得可用后,才尝试重新连接。
在 Spreadbot 类的实例上作为属性可用
state
connecting
connected
disconnected
GET
// Import
import Spreadbot_iOS
// Setup and configuration
let spreadbotREST: SpreadbotREST = SpreadbotREST(config: [
"baseURL": "http://wwww.my-spreadbot-server.com",
"authURL": "http://wwww.my-spreadbot-auth-server.com",
"accessToken": "myAccessToken",
"refreshToken": "myRefreshToken",
"base64Credentials": "MyBase64Credentials",
"log": true // should be false in production
])
spreadbotREST
.getData(path: String, onSuccess: @escaping (Any) -> Void, onError: @escaping (Error) -> Void)
POST
let spreadbotREST: SpreadbotREST = SpreadbotREST(config: [
"baseURL": "http://wwww.my-spreadbot-server.com",
"authURL": "http://wwww.my-spreadbot-auth-server.com",
"accessToken": "myAccessToken",
"refreshToken": "myRefreshToken",
"base64Credentials": "MyBase64Credentials",
"log": true // should be false in production
])
spreadbotREST
.postData(path: String, payload: Data, onSuccess: @escaping (Any) -> Void, onError: @escaping (Error) -> Void)
- watchOS, macOS (OS X) and tvOS
- Linux support
- Add more tests
- SSL support
- Custom queues?
Spreadbot.io 的 Spreadbot_iOS 使用以下库
Spreadbot_iOS 采用 MIT 许可证发布。有关详细信息,请参阅 LICENSE。