测试已测试 | ✓ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布时间最近发布 | 2016年5月 |
SPM支持SPM | ✗ |
由Fancy Pixel、Andrea Mazzini维护。
依赖 | |
ObjectMapper | ~> 1.2 |
CocoaMQTT | ~> 1.0.7 |
SpaceBunny是一种使您和您的设备能够轻松地向服务器或相互发送和交换消息的物联网平台。您可以存储数据,接收及时的事件通知,监控实时流并远程控制您的设备。使用简单,且可以随时轻松扩展。
配置SpaceBunny的Client
实例,使用有效的设备密钥
let client = SpaceBunnyClient(deviceKey: "some-device-key")
如有需要设置客户端
client.useSSL = true
client.delegate = self
将客户端连接到平台。您可以在连接成功或失败时(在这种情况下,您将提供遇到错误的信息)提供名为完成块的回调
client.connect() { error in
if let error == error {
print(error)
}
}
通过提供频道名称,您可以发布消息。您可以通过客户端的channels
属性检索与设备关联的频道
do {
try client.publishOn("data", message: "test")
} catch {
print("Unable to publish")
}
您可以订阅当前设备的收件箱,并在消息可用时接收它们,通过向subscribe
函数提供一个闭包或实现client(_, didReceiveMessage: topic:)
do {
try client.subscribe() { (message, topic) in
print("Received message: \(message ?? "No message")")
}
} catch {
print("Unable to subscribe")
}
// Called when a connection to the platform is established
func spaceBunnyClient(client: SpaceBunnyClient, didConnectTo host: String, port: Int)
// Called when a connection to the platform is ended or failed
func spaceBunnyClient(client: SpaceBunnyClient, didDisconnectWithError error: NSError?)
// Called when a new message is received on the device's inbox
func spaceBunnyClient(client: SpaceBunnyClient, didReceiveMessage message: String?, topic: String)
// Called when a new message is sent
func spaceBunnyClient(client: SpaceBunnyClient, didPublishMessage message: String?, topic: String)
// Called when a the client subscribes to the device's inbox
func spaceBunnyClientiDidSubscribe(client: SpaceBunnyClient)
// Called when a the client unsubscribes from the device's inbox
func spaceBunnyClientDidUnsubscribe(client: SpaceBunnyClient)
The MIT License (MIT)
Copyright (c) 2016 Fancy Pixel S.r.l.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.