Latest 0.9.9
Homepage https://github.com/ckrey/MQTT-Client-Framework
License EPLv1
Platforms ios 6.1, osx 10.10, tvos 9.0, requires ARC
Authors

MQTT-Client-Framework

an Objective-C native MQTT Framework http://mqtt.org

Tested with a long list of brokers

  • mosquitto
  • paho
  • rabbitmq
  • hivemq
  • rsmb
  • mosca
  • vernemq
  • emqtt
  • moquette
  • ActiveMQ
  • Apollo
  • CloudMQTT
  • aws
  • hbmqtt (MQTTv311 only, limitations)
  • aedes

As a CocoaPod

Use the CocoaPod MQTTClient!

Add this to your Podfile:

pod 'MQTTClient'

which is a short for

pod 'MQTTClient/Min'
pod 'MQTTClient/Manager'

The Manager subspec includes the MQTTSessionManager class.

Additionally add this subspec if you want to use MQTT over Websockets:

pod 'MQTTClient/Websocket'

If you want to do your logging with CocoaLumberjack (my suggestion), use

pod 'MQTTClient/MinL'
pod 'MQTTClient/ManagerL'
pod 'MQTTClient/WebsocketL'

instead.

As a dynamic library

Or use the dynamic library created in the MQTTFramework target.

As source

Or include the source from here.

With Carthage

Carthage

github "ckrey/MQTT-Client-Framework"

docs

Documentation generated with doxygen http://doxygen.org in the ./MQTTClient/dist/documentation subdirectory.

Here is the PDF.

You may open the HTML version of the documentation here index.html

Run make install in the ./MQTTClient/dist/documentation/html subdirectory to install the the documentation as a DOCSET on your Mac.

Usage

Create a new client and connect to a broker:

#import "MQTTClient.h"

@interface MyDelegate : ... <MQTTSessionDelegate>
...

        MQTTCFSocketTransport *transport = [[MQTTCFSocketTransport alloc] init];
        transport.host = @"localhost";
        transport.port = 1883;

        MQTTSession *session = [[MQTTSession alloc] init];
        session.transport = transport;

    session.delegate = self;

    [session connectAndWaitTimeout:30];  //this is part of the synchronous API

Subscribe to a topic:

[session subscribeToTopic:@"example/#" atLevel:2 subscribeHandler:^(NSError *error, NSArray<NSNumber *> *gQoss){
    if (error) {
        NSLog(@"Subscription failed %@", error.localizedDescription);
    } else {
        NSLog(@"Subscription sucessfull! Granted Qos: %@", gQoss);
    }
 }]; // this is part of the block API

Add the following to receive messages for the subscribed topics

 - (void)newMessage:(MQTTSession *)session
    data:(NSData *)data
    onTopic:(NSString *)topic
    qos:(MQTTQosLevel)qos
    retained:(BOOL)retained
    mid:(unsigned int)mid {
    // this is one of the delegate callbacks
}

Publish a message to a topic:

[session publishAndWaitData:data
                    onTopic:@"topic"
                     retain:NO
                    qos:MQTTQosLevelAtLeastOnce]; // this is part of the asynchronous API

Comparison MQTT Clients for iOS (incomplete)

Wrapper —- MQTTKit Marquette Moscapsule Musqueteer MQTT-Client MqttSDK CocoaMQTT
Obj-C Obj-C Swift Obj-C Obj-C Obj-C Swift
Library IBM Paho Mosquitto Mosquitto Mosquitto Mosquitto native native native

Latest podspec

{
    "name": "MQTTClient",
    "version": "0.9.9",
    "summary": "iOS, OSX and tvOS native ObjectiveC MQTT Client Framework",
    "homepage": "https://github.com/ckrey/MQTT-Client-Framework",
    "license": {
        "type": "EPLv1",
        "file": "LICENSE"
    },
    "authors": {
        "Christoph Krey": "[email protected]"
    },
    "source": {
        "git": "https://github.com/ckrey/MQTT-Client-Framework.git",
        "tag": "0.9.9",
        "submodules": true
    },
    "requires_arc": true,
    "platforms": {
        "ios": "6.1",
        "osx": "10.10",
        "tvos": "9.0"
    },
    "default_subspecs": "Core",
    "subspecs": [
        {
            "name": "Core",
            "dependencies": {
                "MQTTClient/Min": [],
                "MQTTClient/Manager": []
            }
        },
        {
            "name": "Min",
            "source_files": [
                "MQTTClient/MQTTClient/MQTTCFSocketDecoder.{h,m}",
                "MQTTClient/MQTTClient/MQTTCFSocketEncoder.{h,m}",
                "MQTTClient/MQTTClient/MQTTCFSocketTransport.{h,m}",
                "MQTTClient/MQTTClient/MQTTCoreDataPersistence.{h,m}",
                "MQTTClient/MQTTClient/MQTTDecoder.{h,m}",
                "MQTTClient/MQTTClient/MQTTInMemoryPersistence.{h,m}",
                "MQTTClient/MQTTClient/MQTTLog.{h,m}",
                "MQTTClient/MQTTClient/MQTTStrict.{h,m}",
                "MQTTClient/MQTTClient/MQTTClient.h",
                "MQTTClient/MQTTClient/MQTTMessage.{h,m}",
                "MQTTClient/MQTTClient/MQTTPersistence.h",
                "MQTTClient/MQTTClient/MQTTSSLSecurityPolicy.{h,m}",
                "MQTTClient/MQTTClient/MQTTSSLSecurityPolicyDecoder.{h,m}",
                "MQTTClient/MQTTClient/MQTTSSLSecurityPolicyEncoder.{h,m}",
                "MQTTClient/MQTTClient/MQTTSSLSecurityPolicyTransport.{h,m}",
                "MQTTClient/MQTTClient/MQTTProperties.{h,m}",
                "MQTTClient/MQTTClient/MQTTSession.{h,m}",
                "MQTTClient/MQTTClient/MQTTSessionLegacy.{h,m}",
                "MQTTClient/MQTTClient/MQTTSessionSynchron.{h,m}",
                "MQTTClient/MQTTClient/MQTTTransport.{h,m}"
            ]
        },
        {
            "name": "MinL",
            "dependencies": {
                "CocoaLumberjack": []
            },
            "source_files": [
                "MQTTClient/MQTTClient/MQTTCFSocketDecoder.{h,m}",
                "MQTTClient/MQTTClient/MQTTCFSocketEncoder.{h,m}",
                "MQTTClient/MQTTClient/MQTTCFSocketTransport.{h,m}",
                "MQTTClient/MQTTClient/MQTTCoreDataPersistence.{h,m}",
                "MQTTClient/MQTTClient/MQTTDecoder.{h,m}",
                "MQTTClient/MQTTClient/MQTTInMemoryPersistence.{h,m}",
                "MQTTClient/MQTTClient/MQTTLog.{h,m}",
                "MQTTClient/MQTTClient/MQTTStrict.{h,m}",
                "MQTTClient/MQTTClient/MQTTClient.h",
                "MQTTClient/MQTTClient/MQTTMessage.{h,m}",
                "MQTTClient/MQTTClient/MQTTPersistence.h",
                "MQTTClient/MQTTClient/MQTTSSLSecurityPolicy.{h,m}",
                "MQTTClient/MQTTClient/MQTTSSLSecurityPolicyDecoder.{h,m}",
                "MQTTClient/MQTTClient/MQTTSSLSecurityPolicyEncoder.{h,m}",
                "MQTTClient/MQTTClient/MQTTSSLSecurityPolicyTransport.{h,m}",
                "MQTTClient/MQTTClient/MQTTProperties.{h,m}",
                "MQTTClient/MQTTClient/MQTTSession.{h,m}",
                "MQTTClient/MQTTClient/MQTTSessionLegacy.{h,m}",
                "MQTTClient/MQTTClient/MQTTSessionSynchron.{h,m}",
                "MQTTClient/MQTTClient/MQTTTransport.{h,m}"
            ],
            "xcconfig": {
                "GCC_PREPROCESSOR_DEFINITIONS": "LUMBERJACK=1"
            }
        },
        {
            "name": "Manager",
            "source_files": [
                "MQTTClient/MQTTClient/MQTTSessionManager.{h,m}",
                "MQTTClient/MQTTClient/ReconnectTimer.{h,m}",
                "MQTTClient/MQTTClient/ForegroundReconnection.{h,m}"
            ],
            "dependencies": {
                "MQTTClient/Min": []
            }
        },
        {
            "name": "ManagerL",
            "source_files": [
                "MQTTClient/MQTTClient/MQTTSessionManager.{h,m}",
                "MQTTClient/MQTTClient/ReconnectTimer.{h,m}",
                "MQTTClient/MQTTClient/ForegroundReconnection.{h,m}"
            ],
            "dependencies": {
                "MQTTClient/MinL": []
            },
            "xcconfig": {
                "GCC_PREPROCESSOR_DEFINITIONS": "LUMBERJACK=1"
            }
        },
        {
            "name": "Websocket",
            "source_files": "MQTTClient/MQTTClient/MQTTWebsocketTransport/*.{h,m}",
            "dependencies": {
                "SocketRocket": [],
                "MQTTClient/Min": []
            },
            "requires_arc": true,
            "libraries": "icucore"
        },
        {
            "name": "WebsocketL",
            "source_files": "MQTTClient/MQTTClient/MQTTWebsocketTransport/*.{h,m}",
            "dependencies": {
                "SocketRocket": [],
                "MQTTClient/MinL": []
            },
            "requires_arc": true,
            "libraries": "icucore",
            "xcconfig": {
                "GCC_PREPROCESSOR_DEFINITIONS": "LUMBERJACK=1"
            }
        }
    ]
}

Pin It on Pinterest

Share This