If you are new to the MQTT or just want to refresh your knowledge, please read my overview of the technology first.
The first step to build a stable and reliable iOS application with use of the MQTT protocol is to take some time to determine all use cases and possible scenarios. Based on that the expected specification can be created for the second step - choosing the right broker. The implementation of it on the server is not a task for iOS developer, but it’s important to know what are its functionalities and limitations. Only after that, the proper framework for iOS can be chosen.
There are lots of the MQTT clients available. I had an experience with two of them: CocoaMQTT and MQTT-Client-Framework. However, there is also a third very tempting option, which is Moscapsule. The purpose of this blog post is to compare all three of them especially in terms of differences.
Functionality |
CocoaMQTT |
MQTT-Client-Framework |
Moscapsule |
---|---|---|---|
License |
MIT |
EPL-1.0 |
MIT |
MQTT 3.1 |
✗ |
✓ |
✓ |
MQTT 3.1.1 |
✓ |
✓ |
✓ |
LWT |
✓ |
✓ |
✓ |
SSL/TLS |
✓ |
✓ |
✓ |
Automatic Reconnect |
✓ |
✓ |
✓ |
Disk Persistence |
? |
✓ |
? |
QoS 0 |
✓ |
✓ |
✓ |
QoS 1 |
✓ |
✓ |
✓ |
QoS 2 |
✓ |
✓ |
✓ |
Retained messages |
✓ |
✓ |
✓ |
Authentication |
✓ |
✓ |
✓ |
Throttling |
? |
✓ |
? |
Offline Message Buffering |
✓ |
✓ |
? |
Bulk subscriptions |
✗ |
✓ |
✗ |
Clean/persistent session support |
✓ |
✓ |
✓ |
iOS support |
✓ |
✓ |
✓ |
macOS support |
✓ |
✓ |
✗ |
tvOS support |
✓ |
✓ |
✗ |
Support any broker |
✓ |
✓ |
✗ (only Mosquitto) |
CocoaMQTT is the MQTT client written in Swift 3.1 by Feng Lee, CrazyWisdom, and Alex Yu. It’s been built for iOS, macOS, and tvOS with Xcode 8.3.1. It can be installed with the use of CocoaPods or Carthage.
Pros:
Cons:
Initially built by Christoph Krey MQTT-Client Framework is a powerful tool for most of the possible scenarios. It can be integrated via CocoaPods, Carthage, used as a dynamic library or finally built from the source code. Written in Objective-C is the most mature solution from the three frameworks.
Pros:
Cons:
MQTT client written purely in Swift implemented as a wrapper of Mosquitto library. It covers almost all the features of Mosquitto 1.4.8. Created by a developer hiding under the name of tonary. It can be integrated via CocoaPods or built from the source code.
Pros:
Cons:
The decision which client is the best needs to be done per project and should not be limited only to three frameworks described above. However, some conclusions can be made.
If the project is relatively simple, uses MQTT 3.1.1 protocol and there is no need for bulk subscriptions - CocoaMQTT should be more than enough.
If the project is big, uses MQTT extensively, the final functionalities are not yet determined or the application needs to be stable and reliable at cost of having a big dependency - choose MQTT-Client-Framework.
If the project uses Mosquitto - consider Moscapsule.
Photo by Steven Lelham on Unsplash