MQTT Objective-C client for iOS
C Objective-C Other
Failed to load latest commit information.
MQTTKit.xcodeproj add back mosquitto's WITH_THREADING preprocessor macro Jun 5, 2014
MQTTKit Added Max InFlight Messages settings Dec 17, 2014
MQTTKitTests add cleanSession support May 15, 2014
libmosquitto upgrade to libmosquitto 1.2.3 Feb 18, 2014
.gitignore add libmosquitto 1.2.2 Oct 25, 2013
.travis.yml Update .travis.yml Feb 20, 2014
.xctool-args add .xctool-args Oct 25, 2013
LICENSE Initial commit Oct 25, 2013
MQTTKit.podspec add deployment target 6.0 May 15, 2014


MQTTKit is a modern event-driven Objective-C library for MQTT 3.1.

It uses Mosquitto 1.2.3 library.

An iOS application using MQTTKit is available at MQTTExample.

Project Status

This project is no longer maintained (some context about this decision).

If you encounter bugs with it or need enhancements, you can fork it and modify it as the project is under the Apache License 2.0.

Build Status

Installation Using CocoaPods

On your Podfile add this project:

pod 'MQTTKit', :git => ''

For the first time, run pod install, if you are updating the project invoke pod update.


Import the MQTTKit.h header file

#import <MQTTKit.h>

Send a Message

// create the client with a unique client ID
NSString *clientID = ...
MQTTClient *client = [[MQTTClient alloc] initWithClientId:clientID];

// connect to the MQTT server
[self.client connectToHost:@"" 
         completionHandler:^(NSUInteger code) {
    if (code == ConnectionAccepted) {
        // when the client is connected, send a MQTT message
        [self.client publishString:@"Hello, MQTT"
                 completionHandler:^(int mid) {
            NSLog(@"message has been delivered");

Subscribe to a Topic and Receive Messages

// define the handler that will be called when MQTT messages are received by the client
[self.client setMessageHandler:^(MQTTMessage *message) {
    NSString *text = [message.payloadString];
    NSLog(@"received message %@", text);

// connect the MQTT client
[self.client connectToHost:@""
         completionHandler:^(MQTTConnectionReturnCode code) {
    if (code == ConnectionAccepted) {
        // when the client is connected, subscribe to the topic to receive message.
        [self.client subscribe:@"/MQTTKit/example"

Disconnect from the server

[self.client disconnectWithCompletionHandler:^(NSUInteger code) {
    // The client is disconnected when this completion handler is called
    NSLog(@"MQTT client is disconnected");