MQTTClient
an Objective-C Framework for MQTT
Instance Methods | Properties | List of all members
MQTTSessionManager Class Reference

#import <MQTTSessionManager.h>

Inheritance diagram for MQTTSessionManager:

Instance Methods

(MQTTSessionManager *) - initWithPersistence:maxWindowSize:maxMessages:maxSize:connectInForeground:
 
(void) - connectTo:port:tls:keepalive:clean:auth:user:pass:will:willTopic:willMsg:willQos:willRetainFlag:withClientId:securityPolicy:certificates:protocolLevel:
 
(void) - connectTo:port:tls:keepalive:clean:auth:user:pass:will:willTopic:willMsg:willQos:willRetainFlag:withClientId:securityPolicy:certificates:
 
(void) - connectTo:port:tls:keepalive:clean:auth:user:pass:will:willTopic:willMsg:willQos:willRetainFlag:withClientId:
 
(void) - connectTo:port:tls:keepalive:clean:auth:user:pass:willTopic:will:willQos:willRetainFlag:withClientId:
 
(void) - connectToLast
 
(UInt16) - sendData:topic:qos:retain:
 
(void) - disconnect
 

Properties

id< MQTTSessionManagerDelegate > delegate
 
NSDictionary< NSString *, NSNumber * > * subscriptions
 
NSDictionary< NSString *, NSNumber * > * effectiveSubscriptions
 
MQTTSessionManagerState state
 
NSError * lastErrorCode
 

Detailed Description

SessionManager handles the MQTT session for your application

Method Documentation

§ connectTo:port:tls:keepalive:clean:auth:user:pass:will:willTopic:willMsg:willQos:willRetainFlag:withClientId:()

- (void) connectTo: (NSString *)  host
port: (NSInteger)  port
tls: (BOOL)  tls
keepalive: (NSInteger)  keepalive
clean: (BOOL)  clean
auth: (BOOL)  auth
user: (NSString *)  user
pass: (NSString *)  pass
will: (BOOL)  will
willTopic: (NSString *)  willTopic
willMsg: (NSData *)  willMsg
willQos: (MQTTQosLevel)  willQos
willRetainFlag: (BOOL)  willRetainFlag
withClientId: (NSString *)  clientId 

Convenience alternative to full paramter connectTo

Parameters
hostsee connectTo description
portsee connectTo description
tlssee connectTo description
keepalivesee connectTo description
cleansee connectTo description
authsee connectTo description
usersee connectTo description
passsee connectTo description
willsee connectTo description
willTopicsee connectTo description
willMsgsee connectTo description
willQossee connectTo description
willRetainFlagsee connectTo description
clientIdsee connectTo description

§ connectTo:port:tls:keepalive:clean:auth:user:pass:will:willTopic:willMsg:willQos:willRetainFlag:withClientId:securityPolicy:certificates:()

- (void) connectTo: (NSString *)  host
port: (NSInteger)  port
tls: (BOOL)  tls
keepalive: (NSInteger)  keepalive
clean: (BOOL)  clean
auth: (BOOL)  auth
user: (NSString *)  user
pass: (NSString *)  pass
will: (BOOL)  will
willTopic: (NSString *)  willTopic
willMsg: (NSData *)  willMsg
willQos: (MQTTQosLevel)  willQos
willRetainFlag: (BOOL)  willRetainFlag
withClientId: (NSString *)  clientId
securityPolicy: (MQTTSSLSecurityPolicy *)  securityPolicy
certificates: (NSArray *)  certificates 

Connects to the MQTT broker and stores the parameters for subsequent reconnects

Parameters
hostspecifies the hostname or ip address to connect to. Defaults to "localhost".
portspecifies the port to connect to
tlsspecifies whether to use SSL or not
keepaliveThe 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.
cleanspecifies if the server should discard previous session information.
authspecifies the user and pass parameters should be used for authenthication
useran NSString object containing the user's name (or ID) for authentication. May be nil.
passan NSString object containing the user's password. If userName is nil, password must be nil as well.
willindicates whether a will shall be sent
willTopicthe Will Topic is a string, may be nil
willMsgthe Will Message, might be zero length or nil
willQosspecifies the QoS level to be used when publishing the Will Message.
willRetainFlagindicates if the server should publish the Will Messages with retainFlag.
clientIdThe Client Identifier identifies the Client to the Server. If nil, a random clientId is generated.
securityPolicyA custom SSL security policy or nil.
certificatesAn NSArray of the pinned certificates to use or nil.

§ connectTo:port:tls:keepalive:clean:auth:user:pass:will:willTopic:willMsg:willQos:willRetainFlag:withClientId:securityPolicy:certificates:protocolLevel:()

- (void) connectTo: (NSString *)  host
port: (NSInteger)  port
tls: (BOOL)  tls
keepalive: (NSInteger)  keepalive
clean: (BOOL)  clean
auth: (BOOL)  auth
user: (NSString *)  user
pass: (NSString *)  pass
will: (BOOL)  will
willTopic: (NSString *)  willTopic
willMsg: (NSData *)  willMsg
willQos: (MQTTQosLevel)  willQos
willRetainFlag: (BOOL)  willRetainFlag
withClientId: (NSString *)  clientId
securityPolicy: (MQTTSSLSecurityPolicy *)  securityPolicy
certificates: (NSArray *)  certificates
protocolLevel: (MQTTProtocolVersion)  protocolLevel 

Connects to the MQTT broker and stores the parameters for subsequent reconnects

Parameters
hostspecifies the hostname or ip address to connect to. Defaults to "localhost".
portspecifies the port to connect to
tlsspecifies whether to use SSL or not
keepaliveThe 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.
cleanspecifies if the server should discard previous session information.
authspecifies the user and pass parameters should be used for authenthication
useran NSString object containing the user's name (or ID) for authentication. May be nil.
passan NSString object containing the user's password. If userName is nil, password must be nil as well.
willindicates whether a will shall be sent
willTopicthe Will Topic is a string, may be nil
willMsgthe Will Message, might be zero length or nil
willQosspecifies the QoS level to be used when publishing the Will Message.
willRetainFlagindicates if the server should publish the Will Messages with retainFlag.
clientIdThe Client Identifier identifies the Client to the Server. If nil, a random clientId is generated.
securityPolicyA custom SSL security policy or nil.
certificatesAn NSArray of the pinned certificates to use or nil.
protocolLevelProtocol version of the connection.

§ connectTo:port:tls:keepalive:clean:auth:user:pass:willTopic:will:willQos:willRetainFlag:withClientId:()

- (void) connectTo: (NSString *)  host
port: (NSInteger)  port
tls: (BOOL)  tls
keepalive: (NSInteger)  keepalive
clean: (BOOL)  clean
auth: (BOOL)  auth
user: (NSString *)  user
pass: (NSString *)  pass
willTopic: (NSString *)  willTopic
will: (NSData *)  will
willQos: (MQTTQosLevel)  willQos
willRetainFlag: (BOOL)  willRetainFlag
withClientId: (NSString *)  clientId 

Convenience alternative to full paramter connectTo

Parameters
hostsee connectTo description
portsee connectTo description
tlssee connectTo description
keepalivesee connectTo description
cleansee connectTo description
authsee connectTo description
usersee connectTo description
passsee connectTo description
willTopicthe Will Topic is a string, must not be nil
willthe Will Message, might be zero length
willQossee connectTo description
willRetainFlagsee connectTo description
clientIdsee connectTo description

§ connectToLast()

- (void) connectToLast

Re-Connects to the MQTT broker using the parameters for given in the connectTo method

§ disconnect()

- (void) disconnect

Disconnects gracefully from the MQTT broker

§ initWithPersistence:maxWindowSize:maxMessages:maxSize:connectInForeground:()

- (MQTTSessionManager *) initWithPersistence: (BOOL)  persistent
maxWindowSize: (NSUInteger)  maxWindowSize
maxMessages: (NSUInteger)  maxMessages
maxSize: (NSUInteger)  maxSize
connectInForeground: (BOOL)  connectInForeground 

initWithPersistence sets the MQTTPersistence properties other than default

Parameters
persistentYES or NO (default) to establish file or in memory 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.
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.
maxMessages(a positive number, default is 1024) to limit the number of messages stored. Additional messages published are dropped.
connectInForegroundWhether or not to connect the MQTTSession when the app enters the foreground, and disconnect when it becomes inactive. When NO, the caller is responsible for calling -connectTo: and -disconnect. Defaults to YES.
Returns
the initialized MQTTSessionManager object

§ sendData:topic:qos:retain:()

- (UInt16) sendData: (NSData *)  data
topic: (NSString *)  topic
qos: (MQTTQosLevel)  qos
retain: (BOOL)  retainFlag 

publishes data on a given topic at a specified QoS level and retain flag

Parameters
datathe data to be sent. length may range from 0 to 268,435,455 - 4 - lengthof-topic bytes. Defaults to length 0.
topicthe Topic to identify the data
retainFlagif YES, data is stored on the MQTT broker until overwritten by the next publish with retainFlag = YES
qosspecifies the Quality of Service for the publish qos can be 0, 1, or 2.
Returns
the Message Identifier of the PUBLISH message. Zero if qos 0. If qos 1 or 2, zero if message was dropped
Note
returns immediately.

Property Documentation

§ delegate

- (id<MQTTSessionManagerDelegate>) delegate
readwritenonatomicweak

the delegate receiving incoming messages

§ effectiveSubscriptions

- (NSDictionary<NSString *, NSNumber *>*) effectiveSubscriptions
readnonatomicstrong

effectiveSubscriptions s a dictionary of NSNumber instances indicating the granted MQTTQoSLevel, or 0x80 for subscription failure. The keys are topic filters. effectiveSubscriptions is observable and is updated everytime subscriptions change

...
MQTTSessionManager *manager = [[MQTTSessionManager alloc] init];
manager.delegate = self;
[manager addObserver:self
forKeyPath:@"effectiveSubscriptions"
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
context:nil];
manager.subscriptions = [@{@"#": @(0)} mutableCopy];
[manager connectTo: ...
...
[manager removeObserver:self forKeyPath:@"effectiveSubscriptions"];
...
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary<NSString *,id> *)change
context:(void *)context {
if ([keyPath isEqualToString:@"effectiveSubscriptions"]) {
MQTTSessionManager *manager = (MQTTSessionManager *)object;
DDLogVerbose(@"effectiveSubscriptions changed: %@", manager.effectiveSubscriptions);
}
}

§ lastErrorCode

- (NSError*) lastErrorCode
readnonatomicassign

SessionManager last error code when state equals MQTTSessionManagerStateError

§ state

- (MQTTSessionManagerState) state
readnonatomicassign

SessionManager status

§ subscriptions

- (NSDictionary<NSString *, NSNumber *>*) subscriptions
readwritenonatomicstrong

subscriptions is a dictionary of NSNumber instances indicating the MQTTQoSLevel. The keys are topic filters. The SessionManager subscribes to the given subscriptions after successfull (re-)connect according to the cleansession parameter and the state of the session as indicated by the broker. Setting a new subscriptions dictionary initiates SUBSCRIBE or UNSUBSCRIBE messages by SessionManager by comparing the old and new subscriptions.


The documentation for this class was generated from the following file: