Skip to content

Commit 0cc3f54

Browse files
Merge pull request #1 from launchdarkly/cm-ldclient-delegate
Client delegate implements method userDidUpdate
2 parents 1227f0c + 865e585 commit 0cc3f54

File tree

7 files changed

+52
-3
lines changed

7 files changed

+52
-3
lines changed

Darkly.xcodeproj/project.pbxproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@
489489
CC36AA9C1B6D5FED008200F1 /* Frameworks */,
490490
CC36AA9D1B6D5FED008200F1 /* Resources */,
491491
9E58951B73187EDA355B1E32 /* Copy Pods Resources */,
492+
3475A56B296BBA0BA5BDB7B8 /* Embed Pods Frameworks */,
492493
);
493494
buildRules = (
494495
);
@@ -583,6 +584,21 @@
583584
/* End PBXResourcesBuildPhase section */
584585

585586
/* Begin PBXShellScriptBuildPhase section */
587+
3475A56B296BBA0BA5BDB7B8 /* Embed Pods Frameworks */ = {
588+
isa = PBXShellScriptBuildPhase;
589+
buildActionMask = 2147483647;
590+
files = (
591+
);
592+
inputPaths = (
593+
);
594+
name = "Embed Pods Frameworks";
595+
outputPaths = (
596+
);
597+
runOnlyForDeploymentPostprocessing = 0;
598+
shellPath = /bin/sh;
599+
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-DarklyTests/Pods-DarklyTests-frameworks.sh\"\n";
600+
showEnvVarsInLog = 0;
601+
};
586602
392077F34913B4E6B24527E4 /* Copy Pods Resources */ = {
587603
isa = PBXShellScriptBuildPhase;
588604
buildActionMask = 2147483647;

Darkly/ClientManager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
#import "RequestManager.h"
77

8+
extern NSString *const kLDUserUpdatedNotification;
9+
810
@interface ClientManager : NSObject <RequestManagerDelegate> {
9-
1011
}
1112

1213
@property (nonatomic) BOOL offlineEnabled;

Darkly/ClientManager.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ @implementation ClientManager
1616

1717
@synthesize offlineEnabled;
1818

19+
NSString *const kLDUserUpdatedNotification = @"Darkly.UserUpdatedNotification";
20+
1921
+(ClientManager *)sharedInstance
2022
{
2123
static ClientManager *sharedApiManager = nil;
@@ -180,6 +182,9 @@ - (void)processedConfig:(BOOL)success jsonConfigDictionary:(NSDictionary *)jsonC
180182
PollingManager *pollingMgr = [PollingManager sharedInstance];
181183
DEBUG_LOG(@"ClientManager setting config interval to: %d", configInterval);
182184
pollingMgr.configurationTimerPollingInterval = configInterval;
185+
186+
[[NSNotificationCenter defaultCenter] postNotificationName: kLDUserUpdatedNotification
187+
object: nil];
183188
}
184189
} else {
185190
DEBUG_LOGX(@"ClientManager processedConfig method called after receiving failure response from server");

Darkly/LDClient.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,18 @@
88
@class LDConfig;
99
@class LDUserBuilder;
1010

11+
12+
@protocol ClientDelegate
13+
@required
14+
@property (nonatomic, weak) id<ClientDelegate> delegate;
15+
-(void)userDidUpdate;
16+
@end
17+
1118
@interface LDClient : NSObject
1219

1320
@property(nonatomic, strong, readonly) User *user;
1421
@property(nonatomic, strong, readonly) LDConfig *ldConfig;
22+
@property (nonatomic, assign) id delegate;
1523

1624
+ (id)sharedInstance;
1725

@@ -25,5 +33,4 @@
2533
- (BOOL)flush;
2634
- (BOOL)stopClient;
2735

28-
2936
@end

Darkly/LDClient.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ +(LDClient *)sharedInstance
2424
static dispatch_once_t onceToken;
2525
dispatch_once(&onceToken, ^{
2626
sharedLDClient = [[self alloc] init];
27+
[[NSNotificationCenter defaultCenter] addObserver: self
28+
selector:@selector(configUpdated)
29+
name: kLDUserUpdatedNotification object: nil];
2730
});
2831
return sharedLDClient;
2932
}
@@ -173,4 +176,13 @@ - (BOOL)stopClient {
173176
return NO;
174177
}
175178
}
179+
180+
// Notification handler for ClientManager user updated
181+
-(void)configUpdated {
182+
[self.delegate userDidUpdate];
183+
}
184+
185+
-(void)dealloc {
186+
self.delegate = nil;
187+
}
176188
@end

DarklyTests/LDClientTest.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,5 +168,13 @@ -(void)testCurrentUserBuilderWithStart {
168168
XCTAssertNotNil([[LDClient sharedInstance] currentUserBuilder]);
169169
}
170170

171+
- (void)testDelegateSet {
172+
LDClient *ldClient = [LDClient sharedInstance];
173+
174+
ldClient.delegate = self;
175+
176+
XCTAssertEqualObjects(self, ldClient.delegate);
177+
}
178+
171179

172180
@end

Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ SPEC CHECKSUMS:
7474
OCMock: 28def049ef47f996b515a8eeea958be7ccab2dbb
7575
OHHTTPStubs: 0aec5755528693a165bd616cb79f69387de306a8
7676

77-
COCOAPODS: 0.38.2
77+
COCOAPODS: 0.39.0

0 commit comments

Comments
 (0)