### Connect using WebSocket Secure (wss) Source: https://github.com/emqx/cocoamqtt/blob/master/README.md Example of setting up a secure WebSocket connection (wss) for MQTT. Includes custom SSL validation logic. ```swift import CocoaMQTT import CocoaMQTTWebSocket import Starscream class WebSocketManager { private var mqttClient: CocoaMQTT? var message: String = "" var token: String = "" func setupMQTTClient(with token: String) { let socket = CocoaMQTTWebSocket(uri: "/mqtt") socket.enableSSL = true mqttClient = CocoaMQTT(clientID: token, host: "host", port: 443, socket: socket) mqttClient?.delegate = self } func connect() { guard let mqttClient = mqttClient else { return } mqttClient.connect() } } extension WebSocketManager: CocoaMQTTDelegate { func mqtt(_ mqtt: CocoaMQTT, didReceive trust: SecTrust, completionHandler: @escaping (Bool) -> Void) { // Implement your custom SSL validation logic here. // For example, you might want to always trust the certificate for testing purposes: completionHandler(true) } func mqtt(_ mqtt: CocoaMQTT, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust { if let serverTrust = challenge.protectionSpace.serverTrust { completionHandler(.useCredential, URLCredential(trust: serverTrust)) return } } completionHandler(.performDefaultHandling, nil) } func mqttUrlSession(_ mqtt: CocoaMQTT, didReceiveTrust trust: SecTrust, didReceiveChallenge challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { print("\(#function), \n result:- \(challenge.debugDescription)") } func mqtt(_ mqtt: CocoaMQTT, didPublishAck id: UInt16) { print("Published message with ID: \(id)") } func mqtt(_ mqtt: CocoaMQTT, didUnsubscribeTopics topics: [String]) { print("Unsubscribed from topics: \(topics)") } func mqttDidPing(_ mqtt: CocoaMQTT) { print("MQTT did ping") } func mqttDidReceivePong(_ mqtt: CocoaMQTT) { print("MQTT did receive pong") } func mqttDidDisconnect(_ mqtt: CocoaMQTT, withError err: (any Error)?) { print("Disconnected from MQTT broker with error: \(String(describing: err))") } func mqtt(_ mqtt: CocoaMQTT, didConnectAck ack: CocoaMQTTConnAck) { print("Connected to MQTT broker with acknowledgment: \(ack)") } func mqtt(_ mqtt: CocoaMQTT, didReceiveMessage message: CocoaMQTTMessage, id: UInt16) { if let messageString = message.string { DispatchQueue.main.async { self.message = messageString } print("Received message: \(messageString) on topic: \(message.topic)") } } } ``` -------------------------------- ### Create MQTT 3.1.1 Instance over WebSocket Source: https://github.com/emqx/cocoamqtt/blob/master/README.md Instantiate CocoaMQTT with WebSocket support for MQTT 3.1.1. This is a standard connection setup. ```swift ///MQTT 3.1.1 let websocket = CocoaMQTTWebSocket(uri: "/mqtt") let mqtt = CocoaMQTT(clientID: clientID, host: host, port: 8083, socket: websocket) // ... _ = mqtt.connect() ``` -------------------------------- ### CocoaPods Podfile for WebSockets Source: https://github.com/emqx/cocoamqtt/blob/master/README.md Modify your Podfile to include the CocoaMQTT/WebSockets pod for WebSocket support. Execute 'pod install' after updating. ```ruby use_frameworks! target 'Example' do pod 'CocoaMQTT/WebSockets' end ``` -------------------------------- ### Import CocoaMQTT with Swift Package Manager Source: https://github.com/emqx/cocoamqtt/blob/master/README.md Import the CocoaMQTT library after installing it via Swift Package Manager. ```swift import CocoaMQTT ``` -------------------------------- ### Get SSL Trust (Non-Linux/watchOS) Source: https://github.com/emqx/cocoamqtt/wiki/FoundationStream Retrieves the SSL trust and domain information. This method is only available on non-Linux and non-watchOS platforms. ```swift public func sslTrust() -> (trust: SecTrust?, domain: String?) ``` -------------------------------- ### Get SSL Trust Information Source: https://github.com/emqx/cocoamqtt/wiki/WSStream Retrieves SSL trust and domain information. This method is not available on Linux or watchOS. ```swift func sslTrust() -> (trust: SecTrust?, domain: String?) ``` -------------------------------- ### init() Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTLogger Initializes a new instance of CocoaMQTTLogger. ```APIDOC ## Initializer: init() ### Description Initializes a new instance of the CocoaMQTTLogger class. ### Signature ```swift public override init() ``` ``` -------------------------------- ### init(pkcs12Url:importOptions:) Source: https://github.com/emqx/cocoamqtt/wiki/SSLClientCertificate Designated initializer that creates an SSLClientCertificate instance using a PKCS12 URL and import options. ```APIDOC ## init(pkcs12Url:importOptions:) ### Description Designated init. Initializes an SSLClientCertificate using a PKCS12 URL and import options. ### Parameters #### Path Parameters - **pkcs12Url** (URL) - Required - URL to pkcs12 file containing private key and X.509 certificate (.p12) - **importOptions** (CFDictionary) - Required - A dictionary containing import options. A kSecImportExportPassphrase entry is required at minimum. Only password-based PKCS12 blobs are currently supported. See **SecImportExport.h** ``` -------------------------------- ### init(pkcs12Path:password:) Source: https://github.com/emqx/cocoamqtt/wiki/SSLClientCertificate Convenience initializer that creates an SSLClientCertificate instance using a PKCS12 file path and its password. ```APIDOC ## init(pkcs12Path:password:) ### Description Convenience init. Initializes an SSLClientCertificate using a PKCS12 file path and password. ### Parameters #### Path Parameters - **pkcs12Path** (String) - Required - Path to pkcs12 file containing private key and X.509 certificate (.p12) - **password** (String) - Required - File password, see **kSecImportExportPassphrase** ``` -------------------------------- ### MqttSubscription Initializer Source: https://github.com/emqx/cocoamqtt/wiki/MqttSubscription Initializes a new MqttSubscription with a specified topic. ```APIDOC ## init(topic:) ### Description Initializes a new MqttSubscription with the given topic. ### Parameters #### Path Parameters - **topic** (String) - Required - The MQTT topic to subscribe to. ``` -------------------------------- ### init(pkcs12Url:password:) Source: https://github.com/emqx/cocoamqtt/wiki/SSLClientCertificate Convenience initializer that creates an SSLClientCertificate instance using a PKCS12 URL and its password. ```APIDOC ## init(pkcs12Url:password:) ### Description Convenience init. Initializes an SSLClientCertificate using a PKCS12 URL and password. ### Parameters #### Path Parameters - **pkcs12Url** (URL) - Required - URL to pkcs12 file containing private key and X.509 certificate (.p12) - **password** (String) - Required - File password, see **kSecImportExportPassphrase** ``` -------------------------------- ### MqttSubscription Initializer Source: https://github.com/emqx/cocoamqtt/wiki/MqttSubscription Initializes a new MqttSubscription with a specified topic. ```swift public init(topic: String) ``` -------------------------------- ### Get Certificate Chain from Trust Source: https://github.com/emqx/cocoamqtt/wiki/SSLSecurity Retrieves the certificate chain associated with a given SecTrust object. The chain is returned as an array of Data objects, each representing a certificate. ```swift public func certificateChain(_ trust: SecTrust) -> [Data] ``` -------------------------------- ### Get Public Key Chain from Trust Source: https://github.com/emqx/cocoamqtt/wiki/SSLSecurity Extracts and returns the public keys from the certificate chain of a SecTrust object. This is useful for verifying the authenticity of the server's identity. ```swift public func publicKeyChain(_ trust: SecTrust) -> [SecKey] ``` -------------------------------- ### CocoaMQTT Connect Method Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTT Initiates a connection to the MQTT broker. ```APIDOC ## connect() ### Description Connect to MQTT broker. ### Method `public func connect() -> Bool` ### Returns `Bool` - Returns true if the connection attempt was successful, false otherwise. ``` -------------------------------- ### connect Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTSocketProtocol Establishes a connection to a specified host and port. ```APIDOC ## connect(toHost:​onPort:​) ### Description Initiates a connection to the specified network host and port. ### Method Signature `func connect(toHost host: String, onPort port: UInt16) throws ### Parameters - `host` (String): The hostname or IP address of the server to connect to. - `port` (UInt16): The port number on which the server is listening. ### Throws An error if the connection fails. ``` -------------------------------- ### connect() Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTT5 Initiates a connection to the MQTT broker. Returns a boolean indicating if the socket connection was successful, but not necessarily if the MQTT session is established. ```APIDOC ## connect() ### Description Connect to MQTT broker. ### Method `public func connect() -> Bool` ### Returns - Bool: It indicates whether successfully calling socket connect function. Not yet established correct MQTT session ``` -------------------------------- ### FoundationConnection Connect Method Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTWebSocket_FoundationConnection Initiates the connection to the WebSocket server. ```swift public func connect() ``` -------------------------------- ### Connect to Host Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTSocket Initiates a connection to a specified host and port. This method can throw an error. ```swift public func connect(toHost host: String, onPort port: UInt16) throws ``` -------------------------------- ### Initialize with PKCS12 URL and Import Options Source: https://github.com/emqx/cocoamqtt/wiki/SSLClientCertificate Designated initializer for creating an SSLClientCertificate from a PKCS12 file URL and import options. A password in importOptions is mandatory. ```swift public init(pkcs12Url: URL, importOptions: CFDictionary) throws ``` -------------------------------- ### Initialize with PKCS12 Path and Password Source: https://github.com/emqx/cocoamqtt/wiki/SSLClientCertificate Convenience initializer for creating an SSLClientCertificate from a PKCS12 file path and its password. Requires a valid file path and password. ```swift public convenience init(pkcs12Path: String, password: String) throws ``` -------------------------------- ### connect Source: https://github.com/emqx/cocoamqtt/wiki/FoundationStream Establishes a connection to a specified URL and port with optional timeout, SSL settings, and a completion handler. ```APIDOC ## connect(url:port:timeout:ssl:completion:) ### Description Establishes a connection to a specified URL and port with optional timeout, SSL settings, and a completion handler. ### Method func connect(url: URL, port: Int, timeout: TimeInterval, ssl: SSLSettings, completion: @escaping ((Error?) -> Void)) ### Parameters - **url** (URL) - The URL to connect to. - **port** (Int) - The port number to connect to. - **timeout** (TimeInterval) - The connection timeout in seconds. - **ssl** (SSLSettings) - SSL settings for the connection. - **completion** (@escaping ((Error?) -> Void)) - A closure to be executed upon completion of the connection attempt, receiving an optional Error. ``` -------------------------------- ### CocoaMQTT Connect Method Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTT Initiates a connection to the MQTT broker. Returns a boolean indicating success. ```swift public func connect() -> Bool ``` -------------------------------- ### FoundationConnection Initializers Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTWebSocket_FoundationConnection Initializes a new FoundationConnection instance with a given URL and URLSessionConfiguration. ```APIDOC ## init(url:config:) ### Description Initializes a new FoundationConnection instance. ### Parameters - **url** (URL) - The URL for the WebSocket connection. - **config** (URLSessionConfiguration) - The configuration for the URLSession. ``` -------------------------------- ### WebSocket Convenience Initializer with URL and QoS Source: https://github.com/emqx/cocoamqtt/wiki/WebSocket A convenience initializer for creating a WebSocket instance with a URL, specifying the write queue Quality of Service, and optional protocols. ```swift public convenience init(url: URL, writeQueueQOS: QualityOfService, protocols: [String]? = nil) ``` -------------------------------- ### Connect to Host and Port Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTSocketProtocol Initiates a connection to a specified host and port. This method may throw an error if the connection fails. ```swift func connect(toHost host: String, onPort port: UInt16) throws ``` -------------------------------- ### Define SSLSettings Structure Source: https://github.com/emqx/cocoamqtt/wiki/SSLSettings Defines the main structure for SSL settings. ```swift public struct SSLSettings ``` -------------------------------- ### Initialize with PKCS12 URL and Password Source: https://github.com/emqx/cocoamqtt/wiki/SSLClientCertificate Convenience initializer for creating an SSLClientCertificate from a PKCS12 file URL and its password. Requires a valid URL and password. ```swift public convenience init(pkcs12Url: URL, password: String) throws ``` -------------------------------- ### Connect using MQTT 5.0 with CocoaMQTT Source: https://github.com/emqx/cocoamqtt/blob/master/README.md Instantiate and connect a CocoaMQTT client using MQTT 5.0 protocol. Configure connection properties, username, password, will message, and keep-alive interval. Set the delegate for handling events. ```swift ///MQTT 5.0 let clientID = "CocoaMQTT-" + String(ProcessInfo().processIdentifier) let mqtt5 = CocoaMQTT5(clientID: clientID, host: "broker.emqx.io", port: 1883) let connectProperties = MqttConnectProperties() connectProperties.topicAliasMaximum = 0 connectProperties.sessionExpiryInterval = 0 connectProperties.receiveMaximum = 100 connectProperties.maximumPacketSize = 500 mqtt5.connectProperties = connectProperties mqtt5.username = "test" mqtt5.password = "public" mqtt5.willMessage = CocoaMQTTMessage(topic: "/will", string: "dieout") mqtt5.keepAlive = 60 mqtt5.delegate = self mqtt5.connect() ``` -------------------------------- ### WebSocket Convenience Initializer with URL Source: https://github.com/emqx/cocoamqtt/wiki/WebSocket A convenience initializer for creating a WebSocket instance using a URL and optional protocols. ```swift public convenience init(url: URL, protocols: [String]? = nil) ``` -------------------------------- ### CocoaMQTT5 Initializer Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTT5 Initializes a new CocoaMQTT5 client object with the specified client ID, host, port, and an optional socket. ```APIDOC ## init(clientID:host:port:socket:) ### Description Initial client object. ### Parameters - **clientID** (String) - Required - Client Identifier - **host** (String) - Optional - The MQTT broker host domain or IP address. Default is "localhost" - **port** (UInt16) - Optional - The MQTT service port of host. Default is 1883 - **socket** (CocoaMQTTSocketProtocol) - Optional - The socket to use for communication. Defaults to CocoaMQTTSocket(). ``` -------------------------------- ### Create MQTT 5.0 Instance over WebSocket Source: https://github.com/emqx/cocoamqtt/blob/master/README.md Instantiate CocoaMQTT5 with WebSocket support for MQTT 5.0. Allows setting custom connect properties like topic alias maximum. ```swift ///MQTT 5.0 let websocket = CocoaMQTTWebSocket(uri: "/mqtt") let mqtt5 = CocoaMQTT5(clientID: clientID, host: host, port: 8083, socket: websocket) let connectProperties = MqttConnectProperties() connectProperties.topicAliasMaximum = 0 // ... mqtt5.connectProperties = connectProperties // ... _ = mqtt5.connect() ``` -------------------------------- ### Connect to a URL Source: https://github.com/emqx/cocoamqtt/wiki/FoundationStream Establishes a connection to a specified URL, port, and timeout. Supports SSL and provides a completion handler for errors. ```swift public func connect(url: URL, port: Int, timeout: TimeInterval, ssl: SSLSettings, completion: @escaping ((Error?) -> Void)) ``` -------------------------------- ### Connect to Host with Timeout Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTSocket Initiates a connection to a specified host and port with a custom timeout. This method can throw an error. ```swift public func connect(toHost host: String, onPort port: UInt16, withTimeout timeout: TimeInterval) throws ``` -------------------------------- ### init(identity:identityCertificate:) Source: https://github.com/emqx/cocoamqtt/wiki/SSLClientCertificate Designated initializer that creates an SSLClientCertificate instance using a SecIdentity and SecCertificate. ```APIDOC ## init(identity:identityCertificate:) ### Description Designated init. For more information, see SSLSetCertificate() in Security/SecureTransport.h. Initializes an SSLClientCertificate using a SecIdentity and SecCertificate. ### Parameters #### Path Parameters - **identity** (SecIdentity) - Required - SecIdentityRef, see **kCFStreamSSLCertificates** - **identityCertificate** (SecCertificate) - Required - CFArray of SecCertificateRefs, see **kCFStreamSSLCertificates** ``` -------------------------------- ### Connect to WebSocket Server Source: https://github.com/emqx/cocoamqtt/wiki/WSStream Establishes a connection to a WebSocket server with specified parameters including URL, port, timeout, SSL settings, and a completion handler for connection status. ```swift func connect(url: URL, port: Int, timeout: TimeInterval, ssl: SSLSettings, completion: @escaping ((Error?) -> Void)) ``` -------------------------------- ### DefaultConnectionBuilder Initializer Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTWebSocket_DefaultConnectionBuilder Initializes a new instance of DefaultConnectionBuilder. ```APIDOC ## init() ### Description Initializes a new instance of the `DefaultConnectionBuilder`. ### Method `init()` ### Parameters None ``` -------------------------------- ### Connect using MQTT 3.1.1 with CocoaMQTT Source: https://github.com/emqx/cocoamqtt/blob/master/README.md Instantiate and connect a CocoaMQTT client using MQTT 3.1.1 protocol. Configure username, password, will message, and keep-alive interval. Set the delegate for handling events. ```swift ///MQTT 3.1.1 let clientID = "CocoaMQTT-" + String(ProcessInfo().processIdentifier) let mqtt = CocoaMQTT(clientID: clientID, host: "broker.emqx.io", port: 1883) mqtt.username = "test" mqtt.password = "public" mqtt.willMessage = CocoaMQTTMessage(topic: "/will", string: "dieout") mqtt.keepAlive = 60 mqtt.delegate = self mqtt.connect() ``` -------------------------------- ### SSLCert Initializers Source: https://github.com/emqx/cocoamqtt/wiki/SSLCert Provides documentation for the initializers of the SSLCert class, allowing creation from certificate data or a public key. ```APIDOC ## init(data:) ### Description Designated init for certificates. ### Method `init(data: Data)` ### Parameters - **data** (Data) - The binary data of the certificate. ### Returns A representation security object to be used with. ``` ```APIDOC ## init(key:) ### Description Designated init for public keys. ### Method `init(key: SecKey)` ### Parameters - **key** (SecKey) - The public key to be used. ### Returns A representation security object to be used with. ``` -------------------------------- ### CocoaMQTT Initializer Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTT Initializes a CocoaMQTT client object with specified parameters. Defaults are provided for host and port. ```swift public init(clientID: String, host: String = "localhost", port: UInt16 = 1883, socket: CocoaMQTTSocketProtocol = CocoaMQTTSocket()) ``` -------------------------------- ### Enable SSL Configuration Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTSocketProtocol Configures whether SSL should be enabled for the socket connection. ```swift var enableSSL: Bool ``` -------------------------------- ### Use Another Server Reason Code Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTCONNACKReasonCode Indicates that the client should try connecting to a different server. ```swift case useAnotherServer = 0x9C ``` -------------------------------- ### Connect with Timeout Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTSocketProtocol Initiates a connection to a specified host and port with a given timeout. This method may throw an error if the connection fails within the specified time. ```swift func connect(toHost host: String, onPort port: UInt16, withTimeout timeout: TimeInterval) throws ``` -------------------------------- ### buildConnection(forURL:withHeaders:) Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTWebSocket_DefaultConnectionBuilder Builds a CocoaMQTTWebSocketConnection for the given URL and headers. ```APIDOC ## buildConnection(forURL:withHeaders:) ### Description Builds and returns a `CocoaMQTTWebSocketConnection` instance configured with the provided URL and headers. ### Method `buildConnection(forURL: URL, withHeaders: [String: String]) throws -> CocoaMQTTWebSocketConnection` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **url** (URL) - Required - The URL for the WebSocket connection. - **headers** ([String: String]) - Required - A dictionary of headers to include in the connection request. ``` -------------------------------- ### FoundationConnection Initializer Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTWebSocket_FoundationConnection Initializes a new instance of FoundationConnection with a URL and URLSessionConfiguration. ```swift public init(url: URL, config: URLSessionConfiguration) ``` -------------------------------- ### connect with timeout Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTSocketProtocol Establishes a connection to a specified host and port with a specified timeout. ```APIDOC ## connect(toHost:​onPort:​withTimeout:​) ### Description Initiates a connection to the specified network host and port, with a timeout for the connection attempt. ### Method Signature `func connect(toHost host: String, onPort port: UInt16, withTimeout timeout: TimeInterval) throws ### Parameters - `host` (String): The hostname or IP address of the server to connect to. - `port` (UInt16): The port number on which the server is listening. - `timeout` (TimeInterval): The maximum time in seconds to wait for the connection to establish. ### Throws An error if the connection fails or times out. ``` -------------------------------- ### Connect Method for CocoaMQTTWebSocketConnection Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTWebSocketConnection Initiates the connection process for the WebSocket. Call this method to establish a connection. ```swift func connect() ``` -------------------------------- ### Handle MQTT Subscription Results Source: https://github.com/emqx/cocoamqtt/blob/master/README.md Implement this delegate method to receive feedback on subscription attempts. It logs successful subscriptions and any topics that failed to subscribe to. ```swift func mqtt(_ mqtt: CocoaMQTT, didSubscribeTopics success: NSDictionary, failed: [String]) { print("Subscribed to topics: \(success), failed to subscribe to: \(failed)") } ``` -------------------------------- ### subscribe(_:) Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTT Subscribes to multiple MQTT topics by providing a list of topic-QoS tuples. ```APIDOC ## subscribe(_:) ### Description Subscribe to a list of topics ### Method Signature ```swift public func subscribe(_ topics: [(String, CocoaMQTTQoS)]) ``` ### Parameters - **topics** (Array<(String, CocoaMQTTQoS)>) - A list of tuples, where each tuple contains a topic name/filter (String) and its corresponding Quality of Service level (CocoaMQTTQoS). ``` -------------------------------- ### WebSocket Connect Method Source: https://github.com/emqx/cocoamqtt/wiki/WebSocket Initiates the connection to the WebSocket server on a background thread. ```swift open func connect() ``` -------------------------------- ### CocoaMQTT5 SSLSettings Property Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTT5 Provides settings for SSL/TLS configuration. ```swift public var sslSettings: [String: NSObject]? ``` -------------------------------- ### StarscreamConnection Initializer Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTWebSocket_StarscreamConnection Initializes a new StarscreamConnection instance with a given URLRequest. ```APIDOC ## init(request:) ### Description Initializes a new StarscreamConnection instance with a given URLRequest. ### Parameters #### Path Parameters - **request** (URLRequest) - Required - The URLRequest to use for the WebSocket connection. ``` -------------------------------- ### WebSocket Initializers Source: https://github.com/emqx/cocoamqtt/wiki/WebSocket These initializers are used to create a new WebSocket instance with different configuration options. ```APIDOC ## init(request:protocols:stream:) ### Description Used for setting protocols when initializing the WebSocket. ### Parameters - **request** (URLRequest) - The URL request object for the WebSocket connection. - **protocols** ([String]?, optional) - An array of supported protocols. - **stream** (WSStream, optional) - The stream implementation to use. Defaults to `FoundationStream()`. ``` ```APIDOC ## init(url:protocols:) ### Description Initializes a WebSocket connection to the specified URL. ### Parameters - **url** (URL) - The URL for the WebSocket server. - **protocols** ([String]?, optional) - An array of supported protocols. ``` ```APIDOC ## init(url:writeQueueQOS:protocols:) ### Description Initializes a WebSocket connection to the specified URL with a defined quality of service for the write queue. ### Parameters - **url** (URL) - The URL for the WebSocket server. - **writeQueueQOS** (QualityOfService) - The quality of service for the write queue. - **protocols** ([String]?, optional) - An array of supported protocols. ``` -------------------------------- ### WebSocket Initializer with Protocols Source: https://github.com/emqx/cocoamqtt/wiki/WebSocket Initializes a WebSocket instance with a URLRequest, optional protocols, and a WSStream implementation. Used for setting specific protocols during connection. ```swift public init(request: URLRequest, protocols: [String]? = nil, stream: WSStream = FoundationStream()) ``` -------------------------------- ### Initialize CocoaMQTT5Message with String Payload Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTT5Message Initializes a CocoaMQTT5Message with a topic, string payload, QoS, and retained flag. ```swift public init(topic: String, string: String, qos: CocoaMQTTQoS = .qos1, retained: Bool = false) ``` -------------------------------- ### CocoaMQTTWebSocket Initializer Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTWebSocket Initializes a new instance of CocoaMQTTWebSocket. You can optionally provide a custom URI and a connection builder for advanced configuration. ```APIDOC ## init(uri:builder:) ### Description Initializes a new instance of CocoaMQTTWebSocket. ### Parameters - **uri** (String) - Optional: The WebSocket URI to connect to. Defaults to an empty string. - **builder** (ConnectionBuilder) - Optional: A builder object for configuring the WebSocket connection. Defaults to `CocoaMQTTWebSocket.DefaultConnectionBuilder()`. ``` -------------------------------- ### FoundationConnection Methods Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTWebSocket_FoundationConnection Provides methods for connecting, disconnecting, writing data, and handling WebSocket events. ```APIDOC ## connect() ### Description Establishes the WebSocket connection. ### Method `public func connect()` ``` ```APIDOC ## disconnect() ### Description Closes the WebSocket connection. ### Method `public func disconnect()` ``` ```APIDOC ## write(data:handler:) ### Description Writes data to the WebSocket connection. ### Parameters - **data** (Data) - The data to send. - **handler** (@escaping (Error?) -> Void) - A closure to be called when the write operation completes. ### Method `public func write(data: Data, handler: @escaping (Error?) -> Void)` ``` ```APIDOC ## scheduleRead() ### Description Schedules the reading of incoming data from the WebSocket. ### Method `func scheduleRead()` ``` ```APIDOC ## urlSession(_:task:didReceive:completionHandler:) ### Description Delegate method called when the URLSession encounters an authentication challenge. ### Parameters - **session** (URLSession) - The URL session. - **task** (URLSessionTask) - The task that received the challenge. - **challenge** (URLAuthenticationChallenge) - The authentication challenge. - **completionHandler** (@escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) - The completion handler. ### Method `public func urlSession(_ session: URLSession, task: URLSessionTask, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void)` ``` ```APIDOC ## urlSession(_:webSocketTask:didOpenWithProtocol:) ### Description Delegate method called when the WebSocket connection is opened. ### Parameters - **session** (URLSession) - The URL session. - **webSocketTask** (URLSessionWebSocketTask) - The WebSocket task. - **protocol** (String?) - The protocol used for the connection. ### Method `public func urlSession(_ session: URLSession, webSocketTask: URLSessionWebSocketTask, didOpenWithProtocol protocol: String?)` ``` ```APIDOC ## urlSession(_:webSocketTask:didCloseWith:reason:) ### Description Delegate method called when the WebSocket connection is closed. ### Parameters - **session** (URLSession) - The URL session. - **webSocketTask** (URLSessionWebSocketTask) - The WebSocket task. - **closeCode** (URLSessionWebSocketTask.CloseCode) - The close code. - **reason** (Data?) - The reason for closing. ### Method `public func urlSession(_ session: URLSession, webSocketTask: URLSessionWebSocketTask, didCloseWith closeCode: URLSessionWebSocketTask.CloseCode, reason: Data?)` ``` -------------------------------- ### connect(timeout:) Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTT Establishes a connection to the MQTT broker with a specified timeout. Returns a boolean indicating the success of the socket connection, but not necessarily a fully established MQTT session. ```APIDOC ## connect(timeout:) ### Description Connect to MQTT broker ### Method Signature ```swift public func connect(timeout: TimeInterval) -> Bool ``` ### Parameters - **timeout** (TimeInterval) - Connect timeout ### Returns - Bool: Indicates whether the socket connection was successful. Note: This does not guarantee a fully established MQTT session. ``` -------------------------------- ### CocoaMQTT Initializer Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTT Initializes a new CocoaMQTT client object with the specified client ID, host, port, and an optional socket protocol. ```APIDOC ## init(clientID:host:port:socket:) ### Description Initial client object. ### Parameters - **clientID** (String) - Required - Client Identifier - **host** (String) - Optional - The MQTT broker host domain or IP address. Default is "localhost" - **port** (UInt16) - Optional - The MQTT service port of host. Default is 1883 - **socket** (CocoaMQTTSocketProtocol) - Optional - The socket protocol to use for communication. ``` -------------------------------- ### Initialize SSLSecurity with Public Keys Option Source: https://github.com/emqx/cocoamqtt/wiki/SSLSecurity Initializes SSLSecurity, optionally using public keys for validation. This initializer is convenient for loading certificates from the main app bundle. ```swift public convenience init(usePublicKeys: Bool = false) ``` -------------------------------- ### CocoaMQTTWebSocket Initializer Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTWebSocket Initializes a CocoaMQTTWebSocket instance with an optional URI and a ConnectionBuilder. ```swift public init(uri: String = "", builder: ConnectionBuilder = CocoaMQTTWebSocket.DefaultConnectionBuilder()) ``` -------------------------------- ### CocoaMQTTWebSocket Methods Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTWebSocket Methods for managing the MQTT connection lifecycle, including setting delegates, connecting, and disconnecting. ```APIDOC ## Methods ### setDelegate(_:delegateQueue:) #### Description Sets the delegate object that will receive connection events and the dispatch queue on which delegate methods will be called. #### Parameters - **theDelegate** (CocoaMQTTSocketDelegate?) - The delegate object conforming to `CocoaMQTTSocketDelegate`. - **delegateQueue** (DispatchQueue?) - The dispatch queue to use for delegate callbacks. If nil, callbacks are made on the main queue. ``` ```APIDOC ### connect(toHost:onPort:) #### Description Attempts to establish a connection to the specified host and port. #### Parameters - **host** (String) - The hostname or IP address of the MQTT broker. - **port** (UInt16) - The port number to connect to. #### Throws An error if the connection fails. ``` ```APIDOC ### connect(toHost:onPort:withTimeout:) #### Description Attempts to establish a connection to the specified host and port with a specified timeout. #### Parameters - **host** (String) - The hostname or IP address of the MQTT broker. - **port** (UInt16) - The port number to connect to. - **timeout** (TimeInterval) - The maximum time in seconds to wait for the connection to establish. #### Throws An error if the connection fails or times out. ``` ```APIDOC ### disconnect() #### Description Closes the current MQTT connection gracefully. ``` ```APIDOC ### readData(toLength:withTimeout:tag:) #### Description Initiates reading a specific number of bytes from the connection with a timeout. #### Parameters - **length** (UInt) - The number of bytes to read. - **timeout** (TimeInterval) - The maximum time in seconds to wait for the data. - **tag** (Int) - An identifier for this read operation. ``` ```APIDOC ### write(_:withTimeout:tag:) #### Description Writes data to the connection with a specified timeout. #### Parameters - **data** (Data) - The data to be written. - **timeout** (TimeInterval) - The maximum time in seconds to wait for the write operation to complete. - **tag** (Int) - An identifier for this write operation. ``` -------------------------------- ### Import CocoaMQTT and Starscream Source: https://github.com/emqx/cocoamqtt/blob/master/README.md Import necessary libraries for WebSocket support in CocoaMQTT. Required when integrating via Swift Package Manager. ```swift import CocoaMQTT import CocoaMQTTWebSocket import Starscream ``` -------------------------------- ### publish(_:withString:qos:DUP:retained:properties:) Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTT5 Publishes a string message to a specified topic with configurable QoS, DUP flag, retained flag, and properties. ```APIDOC ## publish(_:withString:qos:DUP:retained:properties:) ### Description Publish a message to broker ### Method `@discardableResult public func publish(_ topic: String, withString string: String, qos: CocoaMQTTQoS = .qos1, DUP: Bool = false, retained: Bool = false, properties: MqttPublishProperties) -> Int` ### Parameters - topic (String): Topic Name. It can not contain '\#' or '+' wildcards. - string (String): Payload string. - qos (CocoaMQTTQoS): Qos. Default is Qos1. - retained (Bool): Retained flag. Mark this message as a retained message. Default is false. ### Returns - 0 will be returned, if the message's qos is qos0. - 1-65535 will be returned, if the messages's qos is qos1/qos2. - -1 will be returned, if the messages queue is full. ``` -------------------------------- ### SSL Use Flag Source: https://github.com/emqx/cocoamqtt/wiki/SSLSettings Boolean property to indicate whether SSL should be used for the connection. ```swift public let useSSL: Bool ``` -------------------------------- ### publish(_:) Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTT Publishes a pre-constructed CocoaMQTTMessage object to the broker. ```APIDOC ## publish(_:) ### Description Publish a message to broker ### Method Signature ```swift @discardableResult public func publish(_ message: CocoaMQTTMessage) -> Int ``` ### Parameters - **message** (CocoaMQTTMessage) - The message object to publish. ### Returns - `0` if the message's QoS is `qos0`. - `1-65535` if the message's QoS is `qos1` or `qos2`. - `-1` if the message queue is full. ``` -------------------------------- ### Connect to MQTT Broker Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTT Initiates a connection to the MQTT broker with a specified timeout. Returns a boolean indicating the success of the socket connection, but not necessarily the establishment of a correct MQTT session. ```swift public func connect(timeout: TimeInterval) -> Bool ``` -------------------------------- ### subscribe(_:qos:) Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTT Subscribes to a single MQTT topic with a specified Quality of Service (QoS) level. ```APIDOC ## subscribe(_:qos:) ### Description Subscribe to a MQTT topic ### Method Signature ```swift public func subscribe(_ topic: String, qos: CocoaMQTTQoS = .qos1) ``` ### Parameters - **topic** (String) - The topic name or topic filter to subscribe to. - **qos** (CocoaMQTTQoS) - The desired Quality of Service level. Defaults to `.qos1`. ``` -------------------------------- ### buildConnection(forURL:withHeaders:) Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTWebSocketConnectionBuilder Builds a WebSocket connection for a given URL and headers. ```APIDOC ## buildConnection(forURL:withHeaders:) ### Description Builds a WebSocket connection for a given URL and headers. ### Method func buildConnection(forURL url: URL, withHeaders headers: [String: String]) throws -> CocoaMQTTWebSocketConnection ``` -------------------------------- ### mqtt5(_:didStateChangeTo:) Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTT5Delegate Called when the MQTT5 client's connection state changes. ```APIDOC ## mqtt5(_:didStateChangeTo:) ### Description Called when the MQTT5 client's connection state changes. ### Method Signature ```swift @objc optional func mqtt5(_ mqtt5: CocoaMQTT5, didStateChangeTo state: CocoaMQTTConnState) ``` ### Parameters - `mqtt5` (CocoaMQTT5): The MQTT5 client instance. - `state` (CocoaMQTTConnState): The new connection state. ``` -------------------------------- ### CocoaMQTTMessage Initializers Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTMessage Initializers for creating a CocoaMQTTMessage object. ```APIDOC ## init(topic:string:qos:retained:) ### Description Initializes a new MQTT message with a topic, string payload, QoS level, and retained flag. ### Parameters - **topic** (String) - The MQTT topic for the message. - **string** (String) - The message payload as a string. - **qos** (CocoaMQTTQoS) - The Quality of Service level for the message. Defaults to .qos1. - **retained** (Bool) - Whether the message should be retained by the broker. Defaults to false. ### Method `init` ``` ```APIDOC ## init(topic:payload:qos:retained:) ### Description Initializes a new MQTT message with a topic, byte array payload, QoS level, and retained flag. ### Parameters - **topic** (String) - The MQTT topic for the message. - **payload** ([UInt8]) - The message payload as a byte array. - **qos** (CocoaMQTTQoS) - The Quality of Service level for the message. Defaults to .qos1. - **retained** (Bool) - Whether the message should be retained by the broker. Defaults to false. ### Method `init` ``` -------------------------------- ### MqttSubscription Topic Property Source: https://github.com/emqx/cocoamqtt/wiki/MqttSubscription Represents the MQTT topic for the subscription. ```swift public var topic: String ``` -------------------------------- ### Subscribe to Multiple Topics Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTT5 Subscribes to a list of MQTT topics, each with its own QoS level. ```swift public func subscribe(_ topics: [MqttSubscription]) ``` -------------------------------- ### publish(_:withString:qos:retained:) Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTT Publishes a string message to a specified topic with configurable Quality of Service (QoS) and retained flag. ```APIDOC ## publish(_:withString:qos:retained:) ### Description Publish a message to broker ### Method Signature ```swift @discardableResult public func publish(_ topic: String, withString string: String, qos: CocoaMQTTQoS = .qos1, retained: Bool = false) -> Int ``` ### Parameters - **topic** (String) - Topic Name. It can not contain '\#' or '+' wildcards. - **string** (String) - Payload string. - **qos** (CocoaMQTTQoS) - Quality of Service level. Defaults to `.qos1`. - **retained** (Bool) - Retained flag. Set to true to mark this message as a retained message. Defaults to `false`. ### Returns - `0` if the message's QoS is `qos0`. - `1-65535` if the message's QoS is `qos1` or `qos2`. - `-1` if the message queue is full. ``` -------------------------------- ### Initialize CocoaMQTT5Message with Byte Array Payload Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTT5Message Initializes a CocoaMQTT5Message with a topic, byte array payload, QoS, and retained flag. ```swift public init(topic: String, payload: [UInt8], qos: CocoaMQTTQoS = .qos1, retained: Bool = false) ``` -------------------------------- ### CocoaMQTTSocket Initializer Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTSocket Initializes a new instance of the CocoaMQTTSocket class. ```APIDOC ## init() ### Description Initializes a new instance of the CocoaMQTTSocket class. ### Method `init()` ``` -------------------------------- ### mqtt5(_:didStateChangeTo:) Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTT5Delegate Called when the MQTT5 client's connection state changes. Provides the new connection state. ```swift @objc optional func mqtt5(_ mqtt5: CocoaMQTT5, didStateChangeTo state: CocoaMQTTConnState) ``` -------------------------------- ### Handle Incoming Messages with Closures Source: https://github.com/emqx/cocoamqtt/blob/master/README.md Set a closure to handle incoming MQTT messages, providing the client, message, and message ID. ```swift mqtt.didReceiveMessage = { mqtt, message, id in print("Message received in topic \(message.topic) with payload \(message.string!)") } ``` -------------------------------- ### Default Write Implementations Source: https://github.com/emqx/cocoamqtt/wiki/WebSocketClient Provides default implementations for writing string, data, ping, pong, and disconnecting. ```swift public func write(string: String) ``` ```swift public func write(data: Data) ``` ```swift public func write(ping: Data) ``` ```swift public func write(pong: Data) ``` ```swift public func disconnect() ``` -------------------------------- ### CocoaMQTT5Message Initializers Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTT5Message Initializers for creating a CocoaMQTT5Message instance. You can initialize with a topic and a string payload, or a topic and a byte array payload. ```APIDOC ## Initializers ### `init(topic:string:qos:retained:)` ```swift public init(topic: String, string: String, qos: CocoaMQTTQoS = .qos1, retained: Bool = false) ``` ### `init(topic:payload:qos:retained:)` ```swift public init(topic: String, payload: [UInt8], qos: CocoaMQTTQoS = .qos1, retained: Bool = false) ``` ``` -------------------------------- ### Build WebSocket Connection Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTWebSocketConnectionBuilder Implement this method to construct a WebSocket connection for a given URL and headers. ```swift func buildConnection(forURL url: URL, withHeaders headers: [String: String]) throws -> CocoaMQTTWebSocketConnection ``` -------------------------------- ### Connect with Custom Headers and SSL Source: https://github.com/emqx/cocoamqtt/blob/master/README.md Configure WebSocket connection with custom HTTP headers and enable SSL. Useful for authentication or secure connections. ```swift let websocket = CocoaMQTTWebSocket(uri: "/mqtt") websocket.headers = [ "x-api-key": "value" ] websocket.enableSSL = true let mqtt = CocoaMQTT(clientID: clientID, host: host, port: 8083, socket: websocket) // ... _ = mqtt.connect() ``` -------------------------------- ### Subscribe to Multiple Topics Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTT Subscribes to a list of MQTT topics, each with its own QoS level. The topics are provided as an array of tuples. ```swift public func subscribe(_ topics: [(String, CocoaMQTTQoS)]) ``` -------------------------------- ### mqtt(_:didStateChangeTo:) Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTDelegate Called when the MQTT client's connection state changes. ```APIDOC ## mqtt(_:didStateChangeTo:) ### Description Called when the MQTT client's connection state changes. ### Signature ```swift @objc optional func mqtt(_ mqtt: CocoaMQTT, didStateChangeTo state: CocoaMQTTConnState) ``` ``` -------------------------------- ### StarscreamConnection Initializer Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTWebSocket_StarscreamConnection Initializes a new StarscreamConnection instance with a given URLRequest. This is used to establish the WebSocket connection. ```swift public init(request: URLRequest) ``` -------------------------------- ### Handle WebSocket Connection Source: https://github.com/emqx/cocoamqtt/wiki/WebSocketDelegate Implement this method to be notified when a WebSocket connection is successfully established. ```swift func websocketDidConnect(socket: WebSocketClient) ``` -------------------------------- ### subscribe(_:) Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTT5 Subscribes to a list of topics with their respective QoS levels. ```APIDOC ## subscribe(_:) ### Description Subscribe to a list of topics. ### Method `public func subscribe(_ topics: [MqttSubscription])` ### Parameters - topics ([MqttSubscription]): A list of subscriptions, where each subscription is a tuple of (Topic Name or Topic Filter, Qos). ``` -------------------------------- ### mqttDidPing(_:) Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTDelegate Called when a PINGREQ is sent to the MQTT broker. ```APIDOC ## mqttDidPing(_:) ### Description Called when a PINGREQ is sent to the MQTT broker. ### Signature ```swift func mqttDidPing(_ mqtt: CocoaMQTT) ``` ``` -------------------------------- ### publish(_:DUP:retained:properties:) Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTT5 Publishes a CocoaMQTT5Message to a specified topic with configurable DUP flag, retained flag, and properties. ```APIDOC ## publish(_:DUP:retained:properties:) ### Description Publish a message to broker ### Method `@discardableResult public func publish(_ message: CocoaMQTT5Message, DUP: Bool = false, retained: Bool = false, properties: MqttPublishProperties) -> Int` ### Parameters - message (CocoaMQTT5Message): The message to publish. - DUP (Bool): The DUP flag. - retained (Bool): The retained flag. - properties (MqttPublishProperties): Publish properties. ``` -------------------------------- ### Reason String Property Source: https://github.com/emqx/cocoamqtt/wiki/MqttAuthProperties Provides a reason string associated with the authentication. This property is optional. ```swift public var reasonString: String? ``` -------------------------------- ### Initialize SSLCert with SecKey Source: https://github.com/emqx/cocoamqtt/wiki/SSLCert Initializes an SSLCert object using a public key. This is the designated initializer for public keys. ```swift public init(key: SecKey) ``` -------------------------------- ### mqtt(_:didStateChangeTo:) Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTDelegate Called when the MQTT client's connection state changes. ```swift @objc optional func mqtt(_ mqtt: CocoaMQTT, didStateChangeTo state: CocoaMQTTConnState) ``` -------------------------------- ### CocoaMQTTWebSocketConnectionDelegate Methods Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTWebSocket Delegate methods for handling WebSocket connection events. ```APIDOC ## Delegate Methods ### connection(_:didReceive:completionHandler:) #### Description Called when the connection receives an SSL trust object. This method is part of the `CocoaMQTTWebSocketConnectionDelegate` protocol and is used for SSL certificate validation. #### Parameters - **conn** (CocoaMQTTWebSocketConnection) - The connection object. - **trust** (SecTrust) - The trust object representing the server's certificate. - **completionHandler** (@escaping (Bool) -> Swift.Void) - A closure to be called with a boolean indicating whether the trust is valid. ``` ```APIDOC ### connectionOpened(_:) #### Description Called when the WebSocket connection is successfully opened. #### Parameters - **conn** (CocoaMQTTWebSocketConnection) - The connection object. ``` ```APIDOC ### connectionClosed(_:withError:) #### Description Called when the WebSocket connection is closed, either intentionally or due to an error. #### Parameters - **conn** (CocoaMQTTWebSocketConnection) - The connection object. - **error** (Error?) - An optional error object if the connection was closed due to an error. ``` ```APIDOC ### connection(_:receivedString:) #### Description Called when the connection receives a string message. #### Parameters - **conn** (CocoaMQTTWebSocketConnection) - The connection object. - **string** (String) - The received string message. ``` ```APIDOC ### connection(_:receivedData:) #### Description Called when the connection receives a data message. #### Parameters - **conn** (CocoaMQTTWebSocketConnection) - The connection object. - **data** (Data) - The received data message. ``` -------------------------------- ### mqtt(_:didReceive:completionHandler:) Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTDelegate Optional method to manually validate SSL/TLS server certificates. Called if `allowUntrustCACertificate` is enabled. ```swift @objc optional func mqtt(_ mqtt: CocoaMQTT, didReceive trust: SecTrust, completionHandler: @escaping (Bool) -> Void) ``` -------------------------------- ### mqtt(_:didPublishAck:) Source: https://github.com/emqx/cocoamqtt/wiki/CocoaMQTTDelegate Called when a publish acknowledgment (PUBACK) is received from the MQTT broker. ```APIDOC ## mqtt(_:didPublishAck:) ### Description Called when a publish acknowledgment (PUBACK) is received from the MQTT broker. ### Signature ```swift func mqtt(_ mqtt: CocoaMQTT, didPublishAck id: UInt16) ``` ```