Skip to content

Commit

Permalink
MQTT-Client-Framework 0.3.0
Browse files Browse the repository at this point in the history
>Release date: 2015-10-03

[NEW] provide support for tvOS, OSX and iOS closes #50
[NEW] add messageDelivered delegate message in MQTTSessionManager closes #49
[FIX] clarification of changing subscriptions in MQTTSessionManager closes #47
  • Loading branch information
Christoph Krey committed Oct 3, 2015
1 parent bee66fc commit fca4f17
Show file tree
Hide file tree
Showing 41 changed files with 1,097 additions and 157 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
MQTT-Client-Framework iOS Release Notes
=======================================

## MQTT-Client-Framework 0.3.0
>Release date: 2015-10-03
[NEW] provide support for tvOS, OSX and iOS closes #50
[NEW] add messageDelivered delegate message in MQTTSessionManager closes #49
[FIX] clarification of changing subscriptions in MQTTSessionManager closes #47

## MQTT-Client-Framework 0.2.6
>Release date: 2015-08-25
Expand Down
9 changes: 6 additions & 3 deletions MQTTClient.podspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
Pod::Spec.new do |s|
s.name = "MQTTClient"
s.version = "0.2.6"
s.summary = "IOS native ObjectiveC MQTT Framework"
s.version = "0.3.0"
s.summary = "iOS, OSX and tvOS native ObjectiveC MQTT Framework"
s.homepage = "https://github.com/ckrey/MQTT-Client-Framework"
s.license = { :type => "MIT", :file => "LICENSE" }
s.author = { "Christoph Krey" => "krey.christoph@gmail.com" }
s.source = { :git => "https://github.com/ckrey/MQTT-Client-Framework.git", :tag => "0.2.6" }
s.source = { :git => "https://github.com/ckrey/MQTT-Client-Framework.git", :tag => "0.3.0" }

s.source_files = "MQTTClient/MQTTClient", "MQTTClient/MQTTClient/**/*.{h,m}"
s.requires_arc = true

s.platform = :ios, "6.1", :osx, "10.10", :tvos, "9.0"
s.ios.deployment_target = "6.1"
s.osx.deployment_target = "10.10"
s.tvos.deployment_target = "9.0"
end
644 changes: 641 additions & 3 deletions MQTTClient/MQTTClient.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion MQTTClient/MQTTClient/MQTTPersistence.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ - (MQTTPersistence *)init {
return self;
}


- (NSUInteger)windowSize:(NSString *)clientId {
NSUInteger windowSize = 0;
NSArray *flows = [self allFlowsforClientId:clientId
Expand Down
15 changes: 13 additions & 2 deletions MQTTClient/MQTTClient/MQTTSessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
//

#import <Foundation/Foundation.h>
#ifndef TARGET_OS_MAC
#import <UIKit/UIKit.h>

#endif
#import "MQTTSession.h"

/** delegate gives your application access to received messages
Expand All @@ -33,6 +34,14 @@ typedef NS_ENUM(int, MQTTSessionManagerState) {
@param retained indicates if the data retransmitted from server storage
*/
- (void)handleMessage:(NSData *)data onTopic:(NSString *)topic retained:(BOOL)retained;

@optional

/** gets called when a published message was actually delivered
@param msgID the Message Identifier of the delivered message
@note this method is called after a publish with qos 1 or 2 only
*/
- (void)messageDelivered:(UInt16)msgID;
@end

/** SessionManager handles the MQTT session for your application
Expand All @@ -47,8 +56,10 @@ typedef NS_ENUM(int, MQTTSessionManagerState) {
* The keys are topic filters.
* The SessionManager subscribes to the given subscriptions after successfull (re-)connect
* according to the cleansession parameter and the state of the session as indicated by the broker.
* Setting a new subscriptions dictionary initiates SUBSCRIBE or UNSUBSCRIBE messages by SessionManager
* by comparing the old and new subscriptions.
*/
@property (strong, nonatomic) NSMutableDictionary *subscriptions;
@property (strong, nonatomic) NSDictionary *subscriptions;

/** SessionManager status
*/
Expand Down
37 changes: 27 additions & 10 deletions MQTTClient/MQTTClient/MQTTSessionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,17 @@ @interface MQTTSessionManager()

@property (strong, nonatomic) NSTimer *disconnectTimer;
@property (strong, nonatomic) NSTimer *activityTimer;
#ifndef TARGET_OS_MAC
@property (nonatomic) UIBackgroundTaskIdentifier backgroundTask;
@property (strong, nonatomic) void (^completionHandler)(UIBackgroundFetchResult);
#endif

@property (nonatomic) BOOL persistent;
@property (nonatomic) NSUInteger maxWindowSize;
@property (nonatomic) NSUInteger maxSize;
@property (nonatomic) NSUInteger maxMessages;

@property (strong, nonatomic) NSMutableDictionary *internalSubscriptions;

@end

#define RECONNECT_TIMER 1.0
Expand All @@ -57,8 +60,8 @@ - (id)init
self = [super init];

self.state = MQTTSessionManagerStateStarting;
#ifndef TARGET_OS_MAC
self.backgroundTask = UIBackgroundTaskInvalid;
self.completionHandler = nil;

NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];

Expand All @@ -76,6 +79,7 @@ - (id)init
selector:@selector(appDidBecomeActive)
name:UIApplicationDidBecomeActiveNotification
object:nil];
#endif
return self;
}

Expand All @@ -91,6 +95,7 @@ - (MQTTSessionManager *)initWithPersistence:(BOOL)persistent
return self;
}

#ifndef TARGET_OS_MAC
- (void)appWillResignActive
{
[self disconnect];
Expand All @@ -110,6 +115,7 @@ - (void)appDidBecomeActive
{
[self connectToLast];
}
#endif

- (void)connectTo:(NSString *)host
port:(NSInteger)port
Expand Down Expand Up @@ -301,15 +307,12 @@ - (void)handleEvent:(MQTTSession *)session event:(MQTTSessionEvent)eventCode err
case MQTTSessionEventConnectionClosed:
case MQTTSessionEventConnectionClosedByBroker:
self.state = MQTTSessionManagerStateClosed;
#ifndef TARGET_OS_MAC
if (self.backgroundTask) {
[[UIApplication sharedApplication] endBackgroundTask:self.backgroundTask];
self.backgroundTask = UIBackgroundTaskInvalid;
}
if (self.completionHandler) {
self.completionHandler(UIBackgroundFetchResultNewData);
self.completionHandler = nil;
}

#endif
self.state = MQTTSessionManagerStateStarting;
break;
case MQTTSessionEventProtocolError:
Expand All @@ -335,7 +338,9 @@ - (void)handleEvent:(MQTTSession *)session event:(MQTTSessionEvent)eventCode err

- (void)newMessage:(MQTTSession *)session data:(NSData *)data onTopic:(NSString *)topic qos:(MQTTQosLevel)qos retained:(BOOL)retained mid:(unsigned int)mid
{
[self.delegate handleMessage:data onTopic:topic retained:retained];
if (self.delegate) {
[self.delegate handleMessage:data onTopic:topic retained:retained];
}
}

- (void)connected:(MQTTSession *)session sessionPresent:(BOOL)sessionPresent {
Expand All @@ -347,6 +352,14 @@ - (void)connected:(MQTTSession *)session sessionPresent:(BOOL)sessionPresent {
}
}

- (void)messageDelivered:(MQTTSession *)session msgID:(UInt16)msgID {
if (self.delegate) {
if ([self.delegate respondsToSelector:@selector(messageDelivered:)]) {
[self.delegate messageDelivered:msgID];
}
}
}


- (void)connectToInternal
{
Expand Down Expand Up @@ -376,7 +389,11 @@ - (void)connectToLast
[self connectToInternal];
}

- (void)setSubscriptions:(NSMutableDictionary *)newSubscriptions
- (NSDictionary *)subscriptions {
return self.internalSubscriptions;
}

- (void)setSubscriptions:(NSDictionary *)newSubscriptions
{
if (self.state==MQTTSessionManagerStateConnected) {
for (NSString *topicFilter in self.subscriptions) {
Expand All @@ -393,7 +410,7 @@ - (void)setSubscriptions:(NSMutableDictionary *)newSubscriptions
}
}
}
_subscriptions=newSubscriptions;
_internalSubscriptions=[newSubscriptions mutableCopy];
}

@end
24 changes: 24 additions & 0 deletions MQTTClient/MQTTClientOSXTests/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
24 changes: 24 additions & 0 deletions MQTTClient/MQTTClientTVTests/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
1 change: 0 additions & 1 deletion MQTTClient/MQTTClientTests/MQTTACLTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// Copyright (c) 2015 Christoph Krey. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import "MQTTClient.h"
#import "MQTTClientTests.h"
Expand Down
2 changes: 1 addition & 1 deletion MQTTClient/MQTTClientTests/MQTTClientTests-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.gmail.cky6201.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
Expand Down
2 changes: 1 addition & 1 deletion MQTTClient/MQTTClientTests/MQTTClientTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define MULTI 15 // some test servers are limited in concurrent sessions
#define BULK 99
#define ALOT 1024
#define PERSISTENT true
#define PERSISTENT false

//#define BROKERLIST @[@"local", @"localTls", @"localTlsCerts", @"mosquitto", @"mosquittoTls", @"mosquittoTlsCerts", @"eclipse", @"paho", @"pahotest", @"rabbitmq", @"hivemq", @"rsmb", @"mosca", @"m2m", @"vernemq", @"emqttd", @"moquette", @"activemq", @"apollo", @"cloudmqtt", @"hbmqtt"]
#define BROKERLIST @[@"local"]
Expand Down
1 change: 0 additions & 1 deletion MQTTClient/MQTTClientTests/MQTTSSLSecurityPolicyTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Created by @bobwenx on 15/6/1.
//

#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import "MQTTSSLSecurityPolicy.h"

Expand Down
5 changes: 4 additions & 1 deletion MQTTClient/MQTTClientTests/MQTTSessionManagerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// Copyright (c) 2015 Christoph Krey. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import "MQTTSessionManager.h"
#import "MQTTClientTests.h"
Expand Down Expand Up @@ -124,6 +123,10 @@ - (void)handleMessage:(NSData *)data onTopic:(NSString *)topic retained:(BOOL)re
}
}

- (void)messageDelivered:(UInt16)msgID {
NSLog(@"messageDelivered %d", msgID);
}

- (void)timeout:(NSTimer *)timer {
NSLog(@"timeout s:%d", self.step);
self.step++;
Expand Down
2 changes: 1 addition & 1 deletion MQTTClient/MQTTClientTests/SwiftTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class SwiftTests : XCTestCase, MQTTSessionDelegate {
}

func newMessage(session: MQTTSession!, data: NSData!, onTopic topic: String!, qos: MQTTQosLevel, retained: Bool, mid: UInt32) {
println("Received \(data) on:\(topic) q\(qos) r\(retained) m\(mid)")
print("Received \(data) on:\(topic) q\(qos) r\(retained) m\(mid)")
sessionReceived = true;
}

Expand Down
4 changes: 2 additions & 2 deletions MQTTClient/MQTTClientTests/SwiftTests2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SwiftTests2 : XCTestCase, MQTTSessionDelegate {
)

session!.delegate = self;
session!.persistence.persistent = true;
session!.persistence.persistent = false;

session!.connectToHost("localhost",
port: 1883,
Expand Down Expand Up @@ -79,7 +79,7 @@ class SwiftTests2 : XCTestCase, MQTTSessionDelegate {
}

func newMessage(session: MQTTSession!, data: NSData!, onTopic topic: String!, qos: MQTTQosLevel, retained: Bool, mid: UInt32) {
println("Received \(data) on:\(topic) q\(qos) r\(retained) m\(mid)")
print("Received \(data) on:\(topic) q\(qos) r\(retained) m\(mid)")
sessionReceived = true;
}

Expand Down
Loading

0 comments on commit fca4f17

Please sign in to comment.