测试已测试 | ✓ |
Lang语言 | SwiftSwift |
许可证 | MIT |
释放最后释放 | 2016年7月 |
SPM支持SPM | ✗ |
由Roman Kovtunenko维护。
依赖 | |
SwiftyJSON | ~> 2.3.0 |
SwiftWebSocket | ~> 2.6.0 |
Swift编写的Rails ActionCable客户端的超简单实现。基于swift websocket库:[https://github.com/tidwall/SwiftWebSocket](https://github.com/tidwall/SwiftWebSocket)
// Initiate client with NSMutableURLRequest
let request = NSMutableURLRequest(URL: NSURL(string: "ws://:3000/cable")!)
let client = ActionCableClient(mutableRequest: request)
// Create new channel
let exampleChannel = ActionChannel.init(name: "ExampleChannel")
// callback on message from server
exampleChannel.onMessage = { json in
print(json)
// send unsubscribe event to the server
client.unsubscribeFrom(exampleChannel)
}
// callback on succesfull subsbscription
exampleChannel.onSubscribed = {
print("succesfully subscribed!")
}
// send subscribe to request to server and start listening
client.subscribeTo(exampleChannel)
exampleChannel.perform("say_hello")
Rails服务器示例在此:[https://github.com/tenshilg/ActionCableExample](https://github.com/tenshilg/ActionCableExample)
SwiftyActionCable可通过CocoaPods获取。要安装它,只需将以下行添加到Podfile中
pod "SwiftyActionCable"
Roman Kovtunenko,[保护邮箱地址](#)
SwiftyActionCable可在MIT许可证下使用。有关更多信息,请参阅LICENSE文件。