Bug/nil run loop (#41) currentRunLoop no long IUO Ensure currentRunLoop is not nil before trying to remove it from streams
Bug/nil run loop (#41)
currentRunLoop no long IUO
Ensure currentRunLoop is not nil before trying to remove it from streams
MQTT Client
mqttSession = MQTTSession( host: "localhost", port: 1883, clientID: "swift", // must be unique to the client cleanSession: true, keepAlive: 15, useSSL: false )
mqttSession.connect { error in if error == .none { print("Connected!") } else { print(error.description) } }
let topic = "mytopic" mqttSession.subscribe(to: topic, delivering: .atLeastOnce) { error in if error == .none { print("Subscribed to \(topic)!") } else { print(error.description) } }
let topic = "mytopic" mqttSession.unSubscribe(from: topic) { error in if error == .none { print("Unsubscribed from \(topic)!") } else { print(error.description) } }
let json = ["key" : "value"] let data = try! JSONSerialization.data(withJSONObject: json, options: .prettyPrinted) let topic = "mytopic" mqttSession.publish(data, in: topic, delivering: .atLeastOnce, retain: false) { error in if error == .none { print("Published data in \(topic)!") } else { print(error.description) } }
MQTTSessionDelegate
mqttSession.delegate = self
func mqttDidReceive(message: MQTTMessage, from session: MQTTSession) { print(message.topic) print(message.stringRepresentation) }
func mqttDidDisconnect(session: MQTTSession, error: MQTTSessionError) { if error == .none { print("Successfully disconnected from MQTT broker") } else { print(error.description) } }
Install using CocoaPods by adding the following lines to your Podfile:
target 'MyApp' do use_frameworks! pod 'SwiftMQTT' end
github "aciidb0mb3r/SwiftMQTT"
dependencies: [ .package(url: "https://github.com/aciidb0mb3r/SwiftMQTT.git", from: "3.0.0") ]
MIT
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
SwiftMQTT
MQTT Client
Usage
Create Session
Connect
Subscribe
Unsubscribe
Publish
Conform to
MQTTSessionDelegate
to receive messagesInstallation
CocoaPods
Install using CocoaPods by adding the following lines to your Podfile:
Carthage
Swift Package Manager
License
MIT