Understanding the CocoaMQTT client in Swift 3
The CocoaMQTT client is very easy to use. First, it is necessary to import CocoaMQTT
, create an instance of the CocoaMQTT
class, specify the MQTT connection configuration values, and indicate an instance of a class that conforms to the CocoaMQTTDelegate
protocol. We can call the methods for the created CocoaMQTT
instance to subscribe to topics and publish messages.
Let's take a look at the code that declares the CocoaMQTTDelegate
protocol:
@objc public protocol CocoaMQTTDelegate { func mqtt(_ mqtt: CocoaMQTT, didConnect host: String, port: Int) func mqtt(_ mqtt: CocoaMQTT, didConnectAck ack: CocoaMQTTConnAck) func mqtt(_ mqtt: CocoaMQTT, didPublishMessage message: CocoaMQTTMessage, id: UInt16) func mqtt(_ mqtt: CocoaMQTT, didPublishAck id: UInt16) func mqtt(_ mqtt: CocoaMQTT, didReceiveMessage message: CocoaMQTTMessage, id: UInt16 ) func mqtt(_ mqtt: CocoaMQTT, didSubscribeTopic topic: String) func mqtt(_ mqtt: CocoaMQTT...