MQTTClient
an Objective-C Framework for MQTT
|
#import <MQTTSession.h>
Instance Methods | |
(void) | - connect |
(void) | - connectWithConnectHandler: |
(void) | - disconnect |
(void) | - disconnectWithReturnCode:sessionExpiryInterval:reasonString:userProperty: |
(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) | - closeWithReturnCode:sessionExpiryInterval:reasonString:userProperty:disconnectHandler: |
(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 * | host |
UInt32 | port |
NSString * | clientId |
NSString * | userName |
NSString * | password |
UInt16 | keepAliveInterval |
NSNumber * | serverKeepAlive |
UInt16 | effectiveKeepAlive |
double | dupTimeout |
BOOL | cleanSessionFlag |
BOOL | willFlag |
NSString * | willTopic |
NSData * | willMsg |
MQTTQosLevel | willQoS |
BOOL | willRetainFlag |
MQTTProtocolVersion | protocolLevel |
NSNumber * | sessionExpiryInterval |
NSString * | authMethod |
NSData * | authData |
NSNumber * | requestProblemInformation |
NSNumber * | willDelayInterval |
NSNumber * | requestResponseInformation |
NSNumber * | receiveMaximum |
NSNumber * | topicAliasMaximum |
NSDictionary< NSString *, NSString * > * | userProperty |
NSNumber * | maximumPacketSize |
NSRunLoop * | runLoop |
NSString * | runLoopMode |
MQTTMessage * | connectMessage |
id< MQTTTransport > | transport |
NSArray * | certificates |
BOOL | voip |
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) closeWithReturnCode: | (MQTTReturnCode) | returnCode | |
sessionExpiryInterval: | (NSNumber *) | sessionExpiryInterval | |
reasonString: | (NSString *) | reasonString | |
userProperty: | (NSDictionary< NSString *, NSString * > *) | userProperty | |
disconnectHandler: | (MQTTDisconnectHandler) | disconnectHandler | |
close V5
returnCode | the returncode send to the broker |
sessionExpiryInterval | the time in seconds before the session can be deleted |
reasonString | a string explaining the reason |
userProperty | additional dictionary of user key/value combinations |
disconnectHandler | will be called when the disconnect finished |
- (void) connect |
connect to the given host through the given transport with the given MQTT session parameters asynchronously
- (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 returns nothing and returns immediately. To check the connect results, register as an MQTTSessionDelegate and
|
- (void) disconnect |
disconnect gracefully
- (void) disconnectWithReturnCode: | (MQTTReturnCode) | returnCode | |
sessionExpiryInterval: | (NSNumber *) | sessionExpiryInterval | |
reasonString: | (NSString *) | reasonString | |
userProperty: | (NSDictionary< NSString *, NSString * > *) | userProperty | |
disconnect V5
returnCode | the returncode send to the broker |
sessionExpiryInterval | the time in seconds before the session can be deleted |
reasonString | a string explaining the reason |
userProperty | additional dictionary of user key/value combinations |
- (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 publsh. 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 |
authData specifies the number of seconds after which a session should expire MQTT v5.0
|
readwritenonatomicstrong |
authMethod specifies the number of seconds after which a session should expire MQTT v5.0
|
readwritenonatomicstrong |
certificates an NSArray holding client certificates or nil
|
readwritenonatomicassign |
leanSessionFlag specifies if the server should discard previous session information.
|
readwritenonatomicstrong |
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 |
dupTimeout If PUBACK or PUBREC not received, message will be resent after this interval
|
readnonatomicassign |
effectiveKeepAlive is a time interval measured in seconds It indicates the effective keep alive interval after a successfull connect where keepAliveInterval might have been overridden by the broker.
|
readatomicassign |
host an NSString containing the hostName or IP address of the Server
|
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.
|
readwritenonatomicstrong |
maximumPacketSize specifies the number of seconds after which a session should expire MQTT v5.0
|
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.
|
readatomicassign |
port an unsigned 32 bit integer containing the IP port number of the Server
|
readwritenonatomicassign |
protocolLevel specifies the protocol to be used
|
readwritenonatomicstrong |
receiveMaximum specifies the number of seconds after which a session should expire MQTT v5.0
|
readwritenonatomicstrong |
requestProblemInformation specifies the number of seconds after which a session should expire MQTT v5.0
|
readwritenonatomicstrong |
requestResponseInformation specifies the number of seconds after which a session should expire MQTT v5.0
|
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.
|
readnonatomicstrong |
The serverKeepAlive is a time interval measured in seconds. This value may be set by the broker and overrides keepAliveInterval if present Zero means the broker does not perform any keep alive checks
|
readwritenonatomicstrong |
sessionExpiryInterval specifies the number of seconds after which a session should expire MQTT v5.0
|
readnonatomicassign |
Indicates if the broker found a persistent session when connecting with cleanSession:FALSE
|
readnonatomicassign |
Session status
|
readwritenonatomicstrong |
topicAliasMaximum specifies the number of seconds after which a session should expire MQTT v5.0
|
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.
|
readwritenonatomicstrong |
topicAliasMaximum specifies the number of seconds after which a session should expire MQTT v5.0
|
readwritenonatomicassign |
Require for VoIP background service defaults to NO
|
readwritenonatomicstrong |
willDelayInterval specifies the number of seconds after which a session should expire MQTT v5.0
|
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.