Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to the LaunchDarkly Python SDK will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org).

## [2.1.1] - 2017-1-3
### Added
- Method to get notified with the flag key for which the value had changed

### Fixed
- Background fetch issues fixed

## [2.1.0] - 2016-12-19
### Changed
- Removed AFNetworking
Expand Down
3 changes: 3 additions & 0 deletions Darkly/DarklyConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ extern NSString * const kClientAlreadyStartedExceptionReason;
extern NSString * const kIphone;
extern NSString * const kIpad;
extern NSString * const kUserDictionaryStorageKey;
extern NSString *const kLDUserUpdatedNotification;
extern NSString *const kLDFlagConfigChangedNotification;
extern NSString *const kLDBackgroundFetchInitiated;
extern int const kCapacity;
extern int const kConnectionTimeout;
extern int const kDefaultFlushInterval;
Expand Down
5 changes: 4 additions & 1 deletion Darkly/DarklyConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#import "DarklyConstants.h"

NSString * const kClientVersion = @"2.1.0";
NSString * const kClientVersion = @"2.1.1";
NSString * const kBaseUrl = @"https://app.launchdarkly.com";
NSString * const kEventsUrl = @"https://mobile.launchdarkly.com";
NSString * const kStreamUrl = @"https://stream.launchdarkly.com/mping";
Expand All @@ -19,6 +19,9 @@
NSString * const kIphone = @"iPhone";
NSString * const kIpad = @"iPad";
NSString * const kUserDictionaryStorageKey = @"ldUserModelDictionary";
NSString * const kLDUserUpdatedNotification = @"Darkly.UserUpdatedNotification";
NSString * const kLDBackgroundFetchInitiated = @"Darkly.BackgroundFetchInitiated";
NSString *const kLDFlagConfigChangedNotification = @"Darkly.FlagConfigChangedNotification";
int const kCapacity = 100;
int const kConnectionTimeout = 10;
int const kDefaultFlushInterval = 30;
Expand Down
3 changes: 2 additions & 1 deletion Darkly/LDClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@


@protocol ClientDelegate <NSObject>
@required
@optional
-(void)userDidUpdate;
-(void)featureFlagDidUpdate:(NSString *)key;
@end

@interface LDClient : NSObject
Expand Down
15 changes: 13 additions & 2 deletions Darkly/LDClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ +(LDClient *)sharedInstance
dispatch_once(&onceToken, ^{
sharedLDClient = [[self alloc] init];
[[NSNotificationCenter defaultCenter] addObserver: sharedLDClient
selector:@selector(configUpdated)
selector:@selector(userUpdated)
name: kLDUserUpdatedNotification object: nil];
[[NSNotificationCenter defaultCenter] addObserver: sharedLDClient
selector:@selector(configFlagUpdated:)
name:kLDFlagConfigChangedNotification object:nil];
});
return sharedLDClient;
}
Expand Down Expand Up @@ -275,12 +278,20 @@ - (BOOL)stopClient {
}

// Notification handler for ClientManager user updated
-(void)configUpdated {
-(void)userUpdated {
if (self.delegate && [self.delegate respondsToSelector:@selector(userDidUpdate)]) {
[self.delegate userDidUpdate];
}
}

// Notification handler for DataManager config flag update
-(void)configFlagUpdated:(NSNotification *)notification {
NSString *keyValue = notification.userInfo;
if (self.delegate && [self.delegate respondsToSelector:@selector(featureFlagDidUpdate:)]) {
[self.delegate featureFlagDidUpdate:keyValue];
}
}

-(void)dealloc {
self.delegate = nil;
}
Expand Down
3 changes: 0 additions & 3 deletions Darkly/LDClientManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
#import <UIKit/UIKit.h>
#import <DarklyEventSource/EventSource.h>

extern NSString *const kLDUserUpdatedNotification;
extern NSString *const kLDBackgroundFetchInitiated;

@interface LDClientManager : NSObject <RequestManagerDelegate, UIApplicationDelegate> {
}

Expand Down
5 changes: 1 addition & 4 deletions Darkly/LDClientManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ @implementation LDClientManager

@synthesize offlineEnabled, eventSource;

NSString *const kLDUserUpdatedNotification = @"Darkly.UserUpdatedNotification";
NSString *const kLDBackgroundFetchInitiated = @"Darkly.BackgroundFetchInitiated";

+(LDClientManager *)sharedInstance {
static LDClientManager *sharedApiManager = nil;
static dispatch_once_t onceToken;
Expand All @@ -27,7 +24,7 @@ +(LDClientManager *)sharedInstance {

[[NSNotificationCenter defaultCenter] addObserver:sharedApiManager selector:@selector(willEnterForeground) name:UIApplicationDidBecomeActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:sharedApiManager selector:@selector(willEnterBackground) name:UIApplicationWillResignActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:sharedApiManager selector:@selector(syncWithServerForEvents) name:kLDBackgroundFetchInitiated object:nil];
[[NSNotificationCenter defaultCenter] addObserver:sharedApiManager selector:@selector(syncWithServerForConfig) name:kLDBackgroundFetchInitiated object:nil];

});
return sharedApiManager;
Expand Down
2 changes: 2 additions & 0 deletions Darkly/LDFlagConfigModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

@interface LDFlagConfigModel : NSObject <NSCoding>

extern NSString * const kFeaturesJsonDictionaryKey;

@property (nullable, nonatomic, strong) NSDictionary *featuresJsonDictionary;

- (nonnull id)initWithDictionary:(nonnull NSDictionary *)dictionary;
Expand Down
2 changes: 1 addition & 1 deletion Darkly/LDFlagConfigModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import "LDFlagConfigModel.h"
#import "LDUtil.h"

static NSString * const kFeaturesJsonDictionaryKey = @"featuresJsonDictionary";
NSString * const kFeaturesJsonDictionaryKey = @"featuresJsonDictionary";

static NSString * const kFeaturesJsonDictionaryServerKey = @"items";

Expand Down
14 changes: 14 additions & 0 deletions Darkly/Models/LDDataManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
#import "LDDataManager.h"
#import "LDEventModel.h"
#import "LDUtil.h"
#import "LDFlagConfigModel.h"

int const kUserCacheSize = 5;

static NSString * const kFlagKey = @"flagkey";

@interface LDDataManager()

@property (strong, nonatomic) NSMutableArray *eventsArray;
Expand Down Expand Up @@ -59,16 +62,19 @@ -(void) saveUser: (LDUserModel *) user {
LDUserModel *resultUser = [userDictionary objectForKey:user.key];
if (resultUser) {
// User is found
[self compareConfigForUser:resultUser withNewUser:user];
resultUser = user;
resultUser.updatedAt = [NSDate date];
} else {
// User is not found so need to create and purge old users
[self compareConfigForUser:nil withNewUser:user];
[self purgeOldUser: userDictionary];
user.updatedAt = [NSDate date];
[userDictionary setObject:user forKey:user.key];
}
} else {
// No Dictionary exists so create
[self compareConfigForUser:nil withNewUser:user];
userDictionary = [[NSMutableDictionary alloc] init];
[userDictionary setObject:user forKey:user.key];
}
Expand All @@ -88,6 +94,14 @@ -(LDUserModel *)findUserWithkey: (NSString *)key {
return resultUser;
}

- (void)compareConfigForUser:(LDUserModel *)user withNewUser:(LDUserModel *)newUser {
for (NSString *key in [[newUser.config dictionaryValue] objectForKey:kFeaturesJsonDictionaryKey]) {
if(user == nil || ![[newUser.config configFlagValue:key] isEqual:[user.config configFlagValue:key]]) {
[[NSNotificationCenter defaultCenter] postNotificationName:kLDFlagConfigChangedNotification object:nil userInfo:key];
}
}
}

- (void)storeUserDictionary:(NSDictionary *)userDictionary {
NSMutableDictionary *archiveDictionary = [[NSMutableDictionary alloc] init];
for (NSString *key in userDictionary) {
Expand Down
4 changes: 2 additions & 2 deletions LaunchDarkly.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "LaunchDarkly"
s.version = "2.1.0"
s.version = "2.1.1"
s.summary = "iOS SDK for LaunchDarkly"

s.description = <<-DESC
Expand Down Expand Up @@ -74,7 +74,7 @@ Pod::Spec.new do |s|
# Supports git, hg, bzr, svn and HTTP.
#

s.source = { :git => "https://github.com/launchdarkly/ios-client.git", :tag => "2.1.0" }
s.source = { :git => "https://github.com/launchdarkly/ios-client.git", :tag => "2.1.1" }


# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
Expand Down