
MQTT-Client-Framework - MQTT Client Library Encyclopedia

Short info
MQTT-Client-Framework | |
---|---|
Language | Objective-C |
License | Eclipse Public License - v 1.0 |
Website | github.com/ckrey/MQTT-Client-Framework |
API Style | Asynchronous and Blocking |
Description
MQTT-Client-Framework is a native Objective-C iOS library. It uses CFNetwork for networking and CoreData for persistence. It is a complete implementation of MQTT 3.1.1 and supports TLS. Three flavors of API are available:A simple blocking API, an elaborate low level callback based API as well as a session manager which takes care of the iOS specific app life cycle.
When I started in 2013 developing the library based on the work of 2lemetry, there was no iOS MQTT client library existing which met the criteria for the OwnTracks project, especially TLS support and protocol completeness. Today there are some Objective-C and Swift wrappers for libmosquitto and Swift native implementations available as open source. MQTT-Client-Framework is actively maintained and used in various projects. Contributions are welcome. It integrates well with Swift. The extensive test cases cover a huge percentage of MQTT 3.1.1 test cases for MQTT brokers.
Features
Feature | |
---|---|
MQTT 3.1 | ![]() |
MQTT 3.1.1 | ![]() |
LWT | ![]() |
SSL/TLS | ![]() |
Automatic Reconnect | ![]() |
Disk Persistence | ![]() |
Feature | |
---|---|
QoS 0 | ![]() |
QoS 1 | ![]() |
QoS 2 | ![]() |
Authentication | ![]() |
Throttling | ![]() |
Offline Message Buffering | ![]() |
Usage
Installation
There are 3 options to use MQTT-Client-Framework:
- Use CocoaPods
The simplest way is to add „MQTTClient“ to your Podfile and run „pod update“
- Include Framework
After cloning the repo from github you may add the iOS framework included underto your iOS project.1
…/MQTTClient/dist/MQTTClient.framework
- Include Source
After cloning the repo from github you may add the sources underdirectly to your iOS project.1
…/MQTTClient/MQTTClient
Doxygen generated documentation is part of the repo under
|
|
Connect
|
|
Connect with MQTT 3.1 or MQTT 3.1.1
|
|
protocolLevel specifies the protocol to be used. The value of the Protocol Level field for the version 3.1.1 of the protocol is 4. The value for the version 3.1 is 3.
Connect with LWT
|
|
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.
willTopic If the Will Flag is set to YES, the Will Topic is a string, nil otherwise.
willMsg If the Will Flag is set to YES the Will Message must be specified, nil otherwise.
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 value of Will QoS can be 0 (0x00), 1 (0x01), or 2 (0x02).
Connect with Username / Password
|
|
userName an NSString object containing the user’s name (or ID) for authentication. May be nil.
password an NSString object containing the user’s password. If userName is nil, password must be nil as well.
Publish
|
|
Publish a retained Message
|
|
Subscribe
|
|
Unsubscribe
|
|
Disconnect
|
|
Using TLS / SSL
You may use iOS’ keyChain to validate server certificates:
|
|
Or you may use a custom security policy:
|
|
And you may use client certificates:
|
|
Example Application
You find a full iPhone application MQTTChat in github at https://github.com/ckrey/MQTTChat

MQTTChat implements a chat protocol over MQTT on an MQTT broker of your choice.
The application presents a tab view with 3 tabs to chat within the app or you may use the app on different devices. A separate MQTT session is used in each tab.
The app CONNECTs to the MQTT broker and sends a join
message when the tab is first opened. The MQTT connection can be gracefully DISCONNECTed (after sending a leave
message) and reCONNECTed on user request.
Simple text messages can be entered and send and will be displayed on all other connected clients and tabs.
The app publishes the text messages as UTF8 encoded strings to the MQTT broker to the topic <base>/<devicename>-<tabnumber>
, e.g. MQTTChat/iPhone Simulator-3
. Messages are not retained. Each session subscribes to the topic <base>/#
, e.g. MQTTChat/#
. Both PUBLISH and SUBSCRIBE use QoS 2.
To run the app, you need Xcode 6 and CocoaPods. You may change the connect parameters for your MQTT broker by updating the mqtt.plist
file.


About Christoph Krey
Thanks for this guest blog postChristoph Krey is a freelance network application specialist who designs and implements client/server solutions in corporate environments since 1983. After a career in IT Management, he began his focus on protocols, mobile devices, and distributed applications. Christoph Krey maintains the MQTT client framework and has created MQTTInspector and OwnTracks for iOS.
Follow Christoph on Github
Eclipse Paho Java - MQTT Client Library Encyclopedia