MQTTClient
an Objective-C Framework for MQTT
|
#import <MQTTSession.h>
Instance Methods | |
(void) | - connect |
(void) | - connectWithConnectHandler: |
(void) | - disconnect |
(MQTTSession *) | - init |
(UInt16) | - subscribeToTopic:atLevel: |
(UInt16) | - subscribeToTopic:atLevel:subscribeHandler: |
(UInt16) | - subscribeToTopics: |
(UInt16) | - subscribeToTopics:subscribeHandler: |
(UInt16) | - unsubscribeTopic: |
(UInt16) | - unsubscribeTopic:unsubscribeHandler: |
(UInt16) | - unsubscribeTopics: |
(UInt16) | - unsubscribeTopics:unsubscribeHandler: |
(UInt16) | - publishData:onTopic:retain:qos: |
(UInt16) | - publishData:onTopic:retain:qos:publishHandler: |
(void) | - closeWithDisconnectHandler: |
(void) | - close |
Properties | |
id< MQTTSessionDelegate > | delegate |
id< MQTTPersistence > | persistence |
MQTTConnectHandler | connectHandler |
void(^ | connectionHandler )(MQTTSessionEvent event) |
void(^ | messageHandler )(NSData *message, NSString *topic) |
MQTTSessionStatus | status |
BOOL | sessionPresent |
NSString * | clientId |
NSString * | userName |
NSString * | password |
UInt16 | keepAliveInterval |
BOOL | cleanSessionFlag |
BOOL | willFlag |
NSString * | willTopic |
NSData * | willMsg |
MQTTQosLevel | willQoS |
BOOL | willRetainFlag |
MQTTProtocolVersion | protocolLevel |
NSRunLoop * | runLoop |
NSString * | runLoopMode |
MQTTSSLSecurityPolicy * | securityPolicy |
MQTTMessage * | connectMessage |
id< MQTTTransport > | transport |
NSArray * | certificates |
Session implements the MQTT protocol for your application
- (void) close |
closes an MQTTSession gracefully
- (void) closeWithDisconnectHandler: | (MQTTDisconnectHandler) | disconnectHandler |
closes an MQTTSession gracefully
If the connection was successfully established before, a DISCONNECT is sent.
disconnectHandler | identifies a block which is executed on successfull or unsuccessfull disconnect. Might be nil. error is nil in the case of a successful disconnect |
- (void) connect |
connect to the given host through the given transport with the given MQTT session parameters asynchronously
NSInternalInconsistencyException | if the parameters are invalid |
- (void) connectWithConnectHandler: | (MQTTConnectHandler) | connectHandler |
connects to the specified MQTT server
connectHandler | identifies a block which is executed on successfull or unsuccessfull connect. Might be nil error is nil in the case of a successful connect sessionPresent indicates in MQTT 3.1.1 if persistent session data was present at the server |
- (void) disconnect |
disconnect gracefully
- (MQTTSession *) init |
initialises the MQTT session with default values
- (UInt16) publishData: | (NSData *) | data | |
onTopic: | (NSString *) | topic | |
retain: | (BOOL) | retainFlag | |
qos: | (MQTTQosLevel) | qos | |
publishes data on a given topic at a specified QoS level and retain flag
data | the data to be sent. length may range from 0 to 268,435,455 - 4 - lengthof-topic bytes. Defaults to length 0. |
topic | the Topic to identify the data |
retainFlag | if YES, data is stored on the MQTT broker until overwritten by the next publish with retainFlag = YES |
qos | specifies the Quality of Service for the publish qos can be 0, 1, or 2. |
- (UInt16) publishData: | (NSData *) | data | |
onTopic: | (NSString *) | topic | |
retain: | (BOOL) | retainFlag | |
qos: | (MQTTQosLevel) | qos | |
publishHandler: | (MQTTPublishHandler) | publishHandler | |
publishes data on a given topic at a specified QoS level and retain flag
data | the data to be sent. length may range from 0 to 268,435,455 - 4 - lengthof-topic bytes. Defaults to length 0. |
topic | the Topic to identify the data |
retainFlag | if YES, data is stored on the MQTT broker until overwritten by the next publish with retainFlag = YES |
qos | specifies the Quality of Service for the publish qos can be 0, 1, or 2. |
publishHandler | identifies a block which is executed on successfull or unsuccessfull connect. Might be nil error is nil in the case of a successful connect sessionPresent indicates in MQTT 3.1.1 if persistent session data was present at the server |
- (UInt16) subscribeToTopic: | (NSString *) | topic | |
atLevel: | (MQTTQosLevel) | qosLevel | |
subscribes to a topic at a specific QoS level
topic | see subscribeToTopic:atLevel:subscribeHandler: for description |
qosLevel | see subscribeToTopic:atLevel:subscribeHandler: for description |
- (UInt16) subscribeToTopic: | (NSString *) | topic | |
atLevel: | (MQTTQosLevel) | qosLevel | |
subscribeHandler: | (MQTTSubscribeHandler) | subscribeHandler | |
subscribes to a topic at a specific QoS level
topic | the Topic Filter to subscribe to. |
qosLevel | specifies the QoS Level of the subscription. qosLevel can be 0, 1, or 2. |
subscribeHandler | identifies a block which is executed on successfull or unsuccessfull subscription. Might be nil. error is nil in the case of a successful subscription. In this case gQoss represents an array of grantes Qos |
- (UInt16) subscribeToTopics: | (NSDictionary< NSString *, NSNumber * > *) | topics |
subscribes a number of topics
topics | an NSDictionary<NSString *, NSNumber *> containing the Topic Filters to subscribe to as keys and the corresponding QoS as NSNumber values |
- (UInt16) subscribeToTopics: | (NSDictionary< NSString *, NSNumber * > *) | topics | |
subscribeHandler: | (MQTTSubscribeHandler) | subscribeHandler | |
subscribes a number of topics
topics | an NSDictionary<NSString *, NSNumber *> containing the Topic Filters to subscribe to as keys and the corresponding QoS as NSNumber values |
subscribeHandler | identifies a block which is executed on successfull or unsuccessfull subscription. Might be nil. error is nil in the case of a successful subscription. In this case gQoss represents an array of grantes Qos |
- (UInt16) unsubscribeTopic: | (NSString *) | topic |
unsubscribes from a topic
topic | the Topic Filter to unsubscribe from. |
- (UInt16) unsubscribeTopic: | (NSString *) | topic | |
unsubscribeHandler: | (MQTTUnsubscribeHandler) | unsubscribeHandler | |
unsubscribes from a topic
topic | the Topic Filter to unsubscribe from. |
unsubscribeHandler | identifies a block which is executed on successfull or unsuccessfull subscription. Might be nil. error is nil in the case of a successful subscription. In this case gQoss represents an array of grantes Qos |
- (UInt16) unsubscribeTopics: | (NSArray< NSString * > *) | topics |
unsubscribes from a number of topics
topics | an NSArray<NSString *> of topics to unsubscribe from |
- (UInt16) unsubscribeTopics: | (NSArray< NSString * > *) | topics | |
unsubscribeHandler: | (MQTTUnsubscribeHandler) | unsubscribeHandler | |
unsubscribes from a number of topics
topics | an NSArray<NSString *> of topics to unsubscribe from |
unsubscribeHandler | identifies a block which is executed on successfull or unsuccessfull subscription. Might be nil. error is nil in the case of a successful subscription. In this case gQoss represents an array of grantes Qos |
|
readwritenonatomicstrong |
certificates an NSArray holding client certificates or nil
|
readwritenonatomicassign |
leanSessionFlag specifies if the server should discard previous session information.
|
readwritenonatomicstrong |
see initWithClientId for description
clientId | The Client Identifier identifies the Client to the Server. If nil, a random clientId is generated. |
|
readwritenonatomiccopy |
block called once when connection is established
|
readwriteatomicstrong |
block called when connection is established
|
readwritenonatomicstrong |
for mqttio-OBJC backward compatibility the connect message used is stored here
|
readwritenonatomicweak |
set this member variable to receive delegate messages
|
readwritenonatomicassign |
see keepAliveInterval The Keep Alive is a time interval measured in seconds. The MQTTClient ensures that the interval between Control Packets being sent does not exceed the Keep Alive value. In the absence of sending any other Control Packets, the Client sends a PINGREQ Packet.
|
readwriteatomicstrong |
block called when message is received
|
readwritenonatomicstrong |
see password an NSString object containing the user's password. If userName is nil, password must be nil as well.
|
readwritenonatomicstrong |
Control MQTT persistence by setting the properties of persistence before connecting to an MQTT broker. The settings are specific to a clientId.
persistence.persistent = YES or NO (default) to establish file or in memory persistence. IMPORTANT: set immediately after creating the MQTTSession before calling any other method. Otherwise the default value (NO) will be used for this session.
persistence.maxWindowSize (a positive number, default is 16) to control the number of messages sent before waiting for acknowledgement in Qos 1 or 2. Additional messages are stored and transmitted later.
persistence.maxSize (a positive number of bytes, default is 64 MB) to limit the size of the persistence file. Messages published after the limit is reached are dropped.
persistence.maxMessages (a positive number, default is 1024) to limit the number of messages stored. Additional messages published are dropped.
Messages are deleted after they have been acknowledged.
|
readwritenonatomicassign |
protocolLevel specifies the protocol to be used
|
readwritenonatomicstrong |
runLoop The runLoop where the streams are scheduled. If nil, defaults to [NSRunLoop currentRunLoop].
|
readwritenonatomicstrong |
runLoopMode The runLoopMode where the streams are scheduled. If nil, defaults to NSRunLoopCommonModes.
|
readwritenonatomicstrong |
The security policy used to evaluate server trust for secure connections. (see MQTTSSLSecurityPolicy.h for more detail).
|
readnonatomicassign |
Indicates if the broker found a persistent session when connecting with cleanSession:FALSE
|
readnonatomicassign |
Session status
|
readwritenonatomicstrong |
the transport provider for MQTTClient
assign an in instance of a class implementing the MQTTTransport protocol e.g. MQTTCFSocketTransport before connecting.
|
readwritenonatomicstrong |
see userName an NSString object containing the user's name (or ID) for authentication. May be nil.
|
readwritenonatomicassign |
willFlag If the Will Flag is set to YES this indicates that a Will Message MUST be published by the Server when the Server detects that the Client is disconnected for any reason other than the Client flowing a DISCONNECT Packet.
|
readwritenonatomicstrong |
willMsg If the Will Flag is set to YES the Will Message must be specified, nil otherwise.
|
readwritenonatomicassign |
willQoS specifies the QoS level to be used when publishing the Will Message. If the Will Flag is set to NO, then the Will QoS MUST be set to 0. If the Will Flag is set to YES, the Will QoS MUST be a valid MQTTQosLevel.
|
readwritenonatomicassign |
willRetainFlag indicates if the server should publish the Will Messages with retainFlag. If the Will Flag is set to NO, then the Will Retain Flag MUST be set to NO . If the Will Flag is set to YES: If Will Retain is set to NO, the Serve MUST publish the Will Message as a non-retained publication [MQTT-3.1.2-14]. If Will Retain is set to YES, the Server MUST publish the Will Message as a retained publication [MQTT-3.1.2-15].
|
readwritenonatomicstrong |
willTopic If the Will Flag is set to YES, the Will Topic is a string, nil otherwise.