MQTTClient 0.8.8

MQTTClient 0.8.8

DocsDocumented
TestsTested
LangLanguage Obj-CObjective C
License Custom
ReleasedLast Release Apr 2017

Maintained by Klaas Pieter Annema, Christoph Krey.


Downloads

Total288,157
Week3,845
Month17,910

Installs

Apps3,007
Apps WeekApps This Week 275
Pod Tries3
Test Targets217
Test WeekTests This week 22
Watch Apps3
powered by Segment

GitHub

Stars604
Watchers51
Forks188
Issues94
Contributors25
Pull Requests1

Code

Files37
SizeIntegration Size 392 kb
FrameworkCreates Framework
LOCLines of Code 4,924


  • By
  • Christoph Krey

MQTT-Client-Framework

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

Tested with

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

Howto

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.

Or use the dynamic library created in the MQTTFramework target.

Or include the source from here.

Documentation

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

docs

Documentation generated with doxygen http://doxygen.org

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