#import <MQTTSessionManager.h>
SessionManager handles the MQTT session for your application
§ 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
-
host | see connectTo description |
port | see connectTo description |
tls | see connectTo description |
keepalive | see connectTo description |
clean | see connectTo description |
auth | see connectTo description |
user | see connectTo description |
pass | see connectTo description |
will | see connectTo description |
willTopic | see connectTo description |
willMsg | see connectTo description |
willQos | see connectTo description |
willRetainFlag | see connectTo description |
clientId | see 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
-
host | specifies the hostname or ip address to connect to. Defaults to "localhost". |
port | specifies the port to connect to |
tls | specifies whether to use SSL or not |
keepalive | 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. |
clean | specifies if the server should discard previous session information. |
auth | specifies the user and pass parameters should be used for authenthication |
user | an NSString object containing the user's name (or ID) for authentication. May be nil. |
pass | an NSString object containing the user's password. If userName is nil, password must be nil as well. |
will | indicates whether a will shall be sent |
willTopic | the Will Topic is a string, may be nil |
willMsg | the Will Message, might be zero length or nil |
willQos | specifies the QoS level to be used when publishing the Will Message. |
willRetainFlag | indicates if the server should publish the Will Messages with retainFlag. |
clientId | The Client Identifier identifies the Client to the Server. If nil, a random clientId is generated. |
securityPolicy | A custom SSL security policy or nil. |
certificates | An 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
-
host | specifies the hostname or ip address to connect to. Defaults to "localhost". |
port | specifies the port to connect to |
tls | specifies whether to use SSL or not |
keepalive | 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. |
clean | specifies if the server should discard previous session information. |
auth | specifies the user and pass parameters should be used for authenthication |
user | an NSString object containing the user's name (or ID) for authentication. May be nil. |
pass | an NSString object containing the user's password. If userName is nil, password must be nil as well. |
will | indicates whether a will shall be sent |
willTopic | the Will Topic is a string, may be nil |
willMsg | the Will Message, might be zero length or nil |
willQos | specifies the QoS level to be used when publishing the Will Message. |
willRetainFlag | indicates if the server should publish the Will Messages with retainFlag. |
clientId | The Client Identifier identifies the Client to the Server. If nil, a random clientId is generated. |
securityPolicy | A custom SSL security policy or nil. |
certificates | An NSArray of the pinned certificates to use or nil. |
protocolLevel | Protocol 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
-
host | see connectTo description |
port | see connectTo description |
tls | see connectTo description |
keepalive | see connectTo description |
clean | see connectTo description |
auth | see connectTo description |
user | see connectTo description |
pass | see connectTo description |
willTopic | the Will Topic is a string, must not be nil |
will | the Will Message, might be zero length |
willQos | see connectTo description |
willRetainFlag | see connectTo description |
clientId | see connectTo description |
§ connectToLast()
Re-Connects to the MQTT broker using the parameters for given in the connectTo method
§ 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
-
persistent | YES 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. |
connectInForeground | Whether 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
-
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. |
- 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.
§ 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
...
[manager addObserver:self
forKeyPath:@"effectiveSubscriptions"
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
context:nil];
[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"]) {
}
}
§ lastErrorCode
- (NSError*) lastErrorCode |
|
readnonatomicassign |
SessionManager last error code when state equals MQTTSessionManagerStateError
§ state
- (MQTTSessionManagerState) state |
|
readnonatomicassign |
§ 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: