Chapter 6. Mobile Messaging with MQTT
In this chapter, we will write an iOS application using the MQTTKit library to send and receive messages using the MQTT protocol.
In “Motions Application Using MQTT”, we described the Motions application (Figure 6-1). In this chapter, we will write the iOS application that broadcasts the device motion data and receives alert messages.
Note
Throughout the chapter, we will show all the code required to run the application.
The whole application code can be retrieved from the GitHub repository in the mqtt/ios/ directory.
MQTTKit
This book uses the MQTTKit library for iOS (and Mac OS X) applications. It is a modern Objective-C library that uses ARC and blocks to write messaging clients in a simple fashion. It is based on the Mosquitto project that provides a lower-level C implementation of MQTT.
The source code of this library project is hosted on GitHub.
Create the Motions Project with Xcode
We will use Xcode to create the Locations iOS application.
After Xcode is installed and started, we select “Create a new Xcode project” from its launch screen. The application will be composed of a single view, so we select the Single View Application template in iOS → Application from the template screen, as illustrated in Figure 6-2.
Get Mobile and Web Messaging now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.