Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 2.12.0 #132

Merged
merged 26 commits into from
Apr 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
dac2b02
updates ios-eventsource to version 3.2.1
markpokornycos Apr 4, 2018
a16c442
advances SDK version to 2.11.2
markpokornycos Apr 4, 2018
c02fcea
Update CHANGELOG.md
arun251 Apr 4, 2018
f350b3c
adds maxThrottlingDelaySeconds
markpokornycos Apr 4, 2018
a1c37e1
adds throttler
markpokornycos Apr 5, 2018
824f2da
installs throttler into LDClient
markpokornycos Apr 5, 2018
5a6e7f4
adds logging to LDThrottler
markpokornycos Apr 6, 2018
1799642
installs setOnline completion block
markpokornycos Apr 6, 2018
8d009bd
advances version to 2.12.0
markpokornycos Apr 6, 2018
15b3205
clear warning
markpokornycos Apr 6, 2018
fb20c7d
releases eventsource on stop
markpokornycos Apr 6, 2018
4e723e0
refines throttler debug logs
markpokornycos Apr 6, 2018
dfcaded
adds stop event source log
markpokornycos Apr 6, 2018
a4d9461
retains last setOnline call state
markpokornycos Apr 6, 2018
8830077
update DarklyEventSource to 3.2.2
markpokornycos Apr 6, 2018
42c11ec
moves willGoOnlineAfterDelay to before matching state bailout
markpokornycos Apr 6, 2018
1ce9a21
updates changelog for retain cycle fix
markpokornycos Apr 9, 2018
74ae6a7
updates DarklyEventSource to version 3.2.3
markpokornycos Apr 16, 2018
e8e3f50
fixes update user defect
markpokornycos Apr 17, 2018
831effd
advances version to 2.12.0.2
markpokornycos Apr 17, 2018
d1ef37f
Update DarklyConstants.m
arun251 Apr 21, 2018
8df01c0
Update LaunchDarkly.podspec
arun251 Apr 21, 2018
deeac92
Merge pull request #71 from launchdarkly/fixUpdateUserDefect
arun251 Apr 21, 2018
730c5cc
Merge branch 'next-release' into throttleOnlineCalls
arun251 Apr 21, 2018
ae2cdd2
Merge pull request #69 from launchdarkly/throttleOnlineCalls
arun251 Apr 23, 2018
c22594f
Updated CHANGELOG
arun251 Apr 23, 2018
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
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@

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

## [2.12.0] - 2018-04-22
### Added
- `LDClient` `isOnline` readonly property that reports the online/offline status.
- `LDClient` `setOnline` method to set the online/offline status. `setOnline` may operate asynchronously, so the client calls an optional completion block when the requested operation completes.

### Changed
- Fixed potential memory leak with `DarklyEventSource`.

### Removed
- `LDClient` `online` and `offline` methods.

### Fixed
- Calling `updateUser` on `LDClient` while streaming no longer causes the SDK to request feature flags. The SDK now disconnects from the LaunchDarkly service and reconnects with the updated user.
- Calling `updateUser` on `LDClient` while polling now resets the polling timer after making a feature flag request.

## [2.11.2] - 2018-04-06
### Changed
- Changes the minimum required `DarklyEventSource` to version `3.2.1` in the CocoaPods podspec
- The maximum backoff time for reconnecting to the feature stream is now 1 hour.

## [2.11.1] - 2018-03-26
### Changed
- Changes the minimum required `DarklyEventSource` to version `3.2.0` in the CocoaPods podspec
Expand Down
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "launchdarkly/ios-eventsource" >= 3.2
github "launchdarkly/ios-eventsource" >= 3.2.3
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "launchdarkly/ios-eventsource" "3.2.0"
github "launchdarkly/ios-eventsource" "3.2.3"
30 changes: 30 additions & 0 deletions Darkly.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@
8305EC8A202243D6002F20DB /* nullConfigIsANull-null-withVersion.json in Resources */ = {isa = PBXBuildFile; fileRef = 8305EC89202243D6002F20DB /* nullConfigIsANull-null-withVersion.json */; };
8305EC8C2022440D002F20DB /* nullConfigIsANull-null-withoutVersion.json in Resources */ = {isa = PBXBuildFile; fileRef = 8305EC8B2022440D002F20DB /* nullConfigIsANull-null-withoutVersion.json */; };
8305EC8E20227365002F20DB /* featureFlags-withoutVersions.json in Resources */ = {isa = PBXBuildFile; fileRef = 8305EC8D20227365002F20DB /* featureFlags-withoutVersions.json */; };
830C2AC5207579AC001D645D /* LDThrottler.h in Headers */ = {isa = PBXBuildFile; fileRef = 830C2AC3207579AC001D645D /* LDThrottler.h */; };
830C2AC6207579AC001D645D /* LDThrottler.h in Headers */ = {isa = PBXBuildFile; fileRef = 830C2AC3207579AC001D645D /* LDThrottler.h */; };
830C2AC7207579AC001D645D /* LDThrottler.h in Headers */ = {isa = PBXBuildFile; fileRef = 830C2AC3207579AC001D645D /* LDThrottler.h */; };
830C2AC8207579AC001D645D /* LDThrottler.h in Headers */ = {isa = PBXBuildFile; fileRef = 830C2AC3207579AC001D645D /* LDThrottler.h */; };
830C2AC9207579AC001D645D /* LDThrottler.m in Sources */ = {isa = PBXBuildFile; fileRef = 830C2AC4207579AC001D645D /* LDThrottler.m */; };
830C2ACA207579AC001D645D /* LDThrottler.m in Sources */ = {isa = PBXBuildFile; fileRef = 830C2AC4207579AC001D645D /* LDThrottler.m */; };
830C2ACB207579AC001D645D /* LDThrottler.m in Sources */ = {isa = PBXBuildFile; fileRef = 830C2AC4207579AC001D645D /* LDThrottler.m */; };
830C2ACC207579AC001D645D /* LDThrottler.m in Sources */ = {isa = PBXBuildFile; fileRef = 830C2AC4207579AC001D645D /* LDThrottler.m */; };
830C2ACF20757CE9001D645D /* LDThrottlerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 830C2ACE20757CE9001D645D /* LDThrottlerTest.m */; };
830C2AD220768697001D645D /* LDThrottler+Testable.m in Sources */ = {isa = PBXBuildFile; fileRef = 830C2AD120768697001D645D /* LDThrottler+Testable.m */; };
83258A3D1F323049008C2133 /* LDClientManager+EventSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 83258A3C1F323049008C2133 /* LDClientManager+EventSource.m */; };
83258A401F3244D0008C2133 /* LDUserBuilder+Testable.m in Sources */ = {isa = PBXBuildFile; fileRef = 83258A3F1F3244D0008C2133 /* LDUserBuilder+Testable.m */; };
83258A421F32721A008C2133 /* emptyConfig.json in Resources */ = {isa = PBXBuildFile; fileRef = 83258A411F32721A008C2133 /* emptyConfig.json */; };
Expand Down Expand Up @@ -368,6 +378,11 @@
8305EC8D20227365002F20DB /* featureFlags-withoutVersions.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "featureFlags-withoutVersions.json"; sourceTree = "<group>"; };
830BF92F202A8854006DF9B1 /* NSJSONSerialization+Testable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSJSONSerialization+Testable.h"; sourceTree = "<group>"; };
830BF930202A8855006DF9B1 /* NSJSONSerialization+Testable.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSJSONSerialization+Testable.m"; sourceTree = "<group>"; };
830C2AC3207579AC001D645D /* LDThrottler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LDThrottler.h; sourceTree = "<group>"; };
830C2AC4207579AC001D645D /* LDThrottler.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LDThrottler.m; sourceTree = "<group>"; };
830C2ACE20757CE9001D645D /* LDThrottlerTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LDThrottlerTest.m; sourceTree = "<group>"; };
830C2AD020768697001D645D /* LDThrottler+Testable.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "LDThrottler+Testable.h"; sourceTree = "<group>"; };
830C2AD120768697001D645D /* LDThrottler+Testable.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "LDThrottler+Testable.m"; sourceTree = "<group>"; };
83258A3B1F323049008C2133 /* LDClientManager+EventSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "LDClientManager+EventSource.h"; sourceTree = "<group>"; };
83258A3C1F323049008C2133 /* LDClientManager+EventSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "LDClientManager+EventSource.m"; sourceTree = "<group>"; };
83258A3E1F3244D0008C2133 /* LDUserBuilder+Testable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "LDUserBuilder+Testable.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -589,6 +604,8 @@
690346E61E68990000E45133 /* LDPollingManager.m */,
690346E71E68990000E45133 /* LDRequestManager.h */,
690346E81E68990000E45133 /* LDRequestManager.m */,
830C2AC3207579AC001D645D /* LDThrottler.h */,
830C2AC4207579AC001D645D /* LDThrottler.m */,
690346E91E68990000E45133 /* LDUserBuilder.h */,
690346EA1E68990000E45133 /* LDUserBuilder.m */,
690346EB1E68990000E45133 /* LDUserModel.h */,
Expand All @@ -614,6 +631,7 @@
6903471B1E689B9F00E45133 /* LDUtilTest.m */,
6903471C1E689B9F00E45133 /* LDClientManagerTest.m */,
6903471F1E689B9F00E45133 /* LDConfigTest.m */,
830C2ACE20757CE9001D645D /* LDThrottlerTest.m */,
690347201E689B9F00E45133 /* DarklyXCTestCase.h */,
690347221E689B9F00E45133 /* DarklyXCTestCase.m */,
690346CE1E6872EA00E45133 /* Info.plist */,
Expand Down Expand Up @@ -726,6 +744,8 @@
83EF678C1F98FC9200403126 /* LDFlagConfigModel+Testable.m */,
830BF92F202A8854006DF9B1 /* NSJSONSerialization+Testable.h */,
830BF930202A8855006DF9B1 /* NSJSONSerialization+Testable.m */,
830C2AD020768697001D645D /* LDThrottler+Testable.h */,
830C2AD120768697001D645D /* LDThrottler+Testable.m */,
);
path = Categories;
sourceTree = "<group>";
Expand Down Expand Up @@ -791,6 +811,7 @@
6903470D1E68990000E45133 /* NSDictionary+JSON.h in Headers */,
690347091E68990000E45133 /* LDUtil.h in Headers */,
69BAF40D1E9AAB4800747613 /* Darkly.h in Headers */,
830C2AC5207579AC001D645D /* LDThrottler.h in Headers */,
690346F71E68990000E45133 /* LDClient.h in Headers */,
833D08CB1F3B97EB00BEED83 /* NSThread+MainExecutable.h in Headers */,
83889B171F8F28AB00A4EF69 /* NSURLResponse+Unauthorized.h in Headers */,
Expand Down Expand Up @@ -822,6 +843,7 @@
69A87EAA1E74712800B88B23 /* LDUserBuilder.h in Headers */,
69A87EAE1E74712800B88B23 /* LDUtil.h in Headers */,
69071F801EA2A7CC00497F93 /* Darkly.h in Headers */,
830C2AC8207579AC001D645D /* LDThrottler.h in Headers */,
69A87E9C1E74712800B88B23 /* LDClient.h in Headers */,
833D08CE1F3B97EB00BEED83 /* NSThread+MainExecutable.h in Headers */,
83889B1A1F8F28AB00A4EF69 /* NSURLResponse+Unauthorized.h in Headers */,
Expand Down Expand Up @@ -853,6 +875,7 @@
69BD7E2B1E6C79910056D70F /* LDUserBuilder.h in Headers */,
69BD7E2F1E6C79910056D70F /* LDUtil.h in Headers */,
69071F7F1EA2A7CB00497F93 /* Darkly.h in Headers */,
830C2AC7207579AC001D645D /* LDThrottler.h in Headers */,
69BD7E1D1E6C79910056D70F /* LDClient.h in Headers */,
833D08CD1F3B97EB00BEED83 /* NSThread+MainExecutable.h in Headers */,
83889B191F8F28AB00A4EF69 /* NSURLResponse+Unauthorized.h in Headers */,
Expand Down Expand Up @@ -884,6 +907,7 @@
69F3F6971E6BF82C00079A09 /* LDClient.h in Headers */,
69F3F6AB1E6BF82C00079A09 /* NSDictionary+JSON.h in Headers */,
69071F7E1EA2A7CA00497F93 /* Darkly.h in Headers */,
830C2AC6207579AC001D645D /* LDThrottler.h in Headers */,
69F3F6A31E6BF82C00079A09 /* LDRequestManager.h in Headers */,
833D08CC1F3B97EB00BEED83 /* NSThread+MainExecutable.h in Headers */,
83889B181F8F28AB00A4EF69 /* NSURLResponse+Unauthorized.h in Headers */,
Expand Down Expand Up @@ -1343,6 +1367,7 @@
8305EC6B20221973002F20DB /* LDFlagConfigValue.m in Sources */,
83EF67851F979B4100403126 /* LDEvent+Unauthorized.m in Sources */,
6903470E1E68990000E45133 /* NSDictionary+JSON.m in Sources */,
830C2AC9207579AC001D645D /* LDThrottler.m in Sources */,
690347021E68990000E45133 /* LDPollingManager.m in Sources */,
690346FC1E68990000E45133 /* LDConfig.m in Sources */,
690347061E68990000E45133 /* LDUserBuilder.m in Sources */,
Expand All @@ -1361,6 +1386,7 @@
8349F51E1F19352300B1F3DB /* NSDictionary+StringKey_Matchable.m in Sources */,
839956E820053081009707D1 /* LDUserModel+Testable.m in Sources */,
690347291E689B9F00E45133 /* LDEventModelTest.m in Sources */,
830C2ACF20757CE9001D645D /* LDThrottlerTest.m in Sources */,
690347301E689B9F00E45133 /* LDConfigTest.m in Sources */,
690347261E689B9F00E45133 /* LDUserBuilderTest.m in Sources */,
832C788D1F2977B800E334A2 /* NSString+RemoveWhitespace.m in Sources */,
Expand All @@ -1369,6 +1395,7 @@
6903472B1E689B9F00E45133 /* LDPollingManagerTest.m in Sources */,
83EF67901F99365600403126 /* LDClient+Testable.m in Sources */,
83258A3D1F323049008C2133 /* LDClientManager+EventSource.m in Sources */,
830C2AD220768697001D645D /* LDThrottler+Testable.m in Sources */,
8305EC7A20222B5E002F20DB /* NSObject+LDFlagConfigValueTest.m in Sources */,
83BE938C201A797B00DD1ED9 /* NSJSONSerialization+Testable.m in Sources */,
6903472E1E689B9F00E45133 /* LDClientManagerTest.m in Sources */,
Expand Down Expand Up @@ -1410,6 +1437,7 @@
8305EC6E20221973002F20DB /* LDFlagConfigValue.m in Sources */,
83EF67881F979B4100403126 /* LDEvent+Unauthorized.m in Sources */,
69A87EAF1E74712800B88B23 /* LDUtil.m in Sources */,
830C2ACC207579AC001D645D /* LDThrottler.m in Sources */,
69A87EA71E74712800B88B23 /* LDPollingManager.m in Sources */,
69A87E9F1E74712800B88B23 /* LDClientManager.m in Sources */,
69A87EAD1E74712800B88B23 /* LDUserModel.m in Sources */,
Expand Down Expand Up @@ -1439,6 +1467,7 @@
8305EC6D20221973002F20DB /* LDFlagConfigValue.m in Sources */,
83EF67871F979B4100403126 /* LDEvent+Unauthorized.m in Sources */,
69BD7E301E6C79910056D70F /* LDUtil.m in Sources */,
830C2ACB207579AC001D645D /* LDThrottler.m in Sources */,
69BD7E281E6C79910056D70F /* LDPollingManager.m in Sources */,
69BD7E201E6C79910056D70F /* LDClientManager.m in Sources */,
69BD7E2E1E6C79910056D70F /* LDUserModel.m in Sources */,
Expand Down Expand Up @@ -1468,6 +1497,7 @@
8305EC6C20221973002F20DB /* LDFlagConfigValue.m in Sources */,
83EF67861F979B4100403126 /* LDEvent+Unauthorized.m in Sources */,
69F3F6AA1E6BF82C00079A09 /* LDUtil.m in Sources */,
830C2ACA207579AC001D645D /* LDThrottler.m in Sources */,
69F3F6A21E6BF82C00079A09 /* LDPollingManager.m in Sources */,
69F3F69A1E6BF82C00079A09 /* LDClientManager.m in Sources */,
69F3F6A81E6BF82C00079A09 /* LDUserModel.m in Sources */,
Expand Down
1 change: 1 addition & 0 deletions Darkly/DarklyConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ extern NSInteger const kHTTPStatusCodeUnauthorized;
extern NSInteger const kHTTPStatusCodeMethodNotAllowed;
extern NSInteger const kHTTPStatusCodeNotImplemented;
extern NSInteger const kErrorCodeUnauthorized;
extern NSTimeInterval const kMaxThrottlingDelayInterval;
3 changes: 2 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.11.1";
NSString * const kClientVersion = @"2.12.0";
NSString * const kBaseUrl = @"https://app.launchdarkly.com";
NSString * const kEventsUrl = @"https://mobile.launchdarkly.com";
NSString * const kStreamUrl = @"https://clientstream.launchdarkly.com";
Expand Down Expand Up @@ -44,3 +44,4 @@
NSInteger const kHTTPStatusCodeMethodNotAllowed = 405;
NSInteger const kHTTPStatusCodeNotImplemented = 501;
NSInteger const kErrorCodeUnauthorized = -kHTTPStatusCodeUnauthorized;
NSTimeInterval const kMaxThrottlingDelayInterval = 600.0;
14 changes: 8 additions & 6 deletions Darkly/LDClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

@interface LDClient : NSObject

@property (nonatomic, assign, readonly) BOOL isOnline;
@property(nonatomic, strong, readonly) LDUserModel *ldUser;
@property(nonatomic, strong, readonly) LDConfig *ldConfig;
@property (nonatomic, weak) id<ClientDelegate> delegate;
Expand Down Expand Up @@ -125,17 +126,18 @@
*/
- (LDUserBuilder *)currentUserBuilder;
/**
* Set the client to offline mode. No events will be synced to server.
* Set the client to online/offline mode. When online events will be synced to server. (Default)
*
* @return whether offline mode was successfully updated.
* @param goOnline Desired online/offline mode for the client
*/
- (BOOL)offline;
- (void)setOnline:(BOOL)goOnline;
/**
* Set the client to online mode. Events will be synced to server. (Default)
* Set the client to online/offline mode. When online events will be synced to server. (Default)
*
* @return whether online mode was successfully updated.
* @param goOnline Desired online/offline mode for the client
* @param completion Completion block called when setOnline completes
*/
- (BOOL)online;
- (void)setOnline:(BOOL)goOnline completion:(void(^)(void))completion;
/**
* Sync all events to the server. Events are synced to the server on a
* regular basis, however this will force all stored events from the client
Expand Down
92 changes: 58 additions & 34 deletions Darkly/LDClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@
#import "LDPollingManager.h"
#import "DarklyConstants.h"
#import "NSThread+MainExecutable.h"
#import "LDThrottler.h"

@interface LDClient()
@property (nonatomic, assign) BOOL isOnline;
@property(nonatomic, strong) LDUserModel *ldUser;
@property(nonatomic, strong) LDConfig *ldConfig;
@property (nonatomic, assign) BOOL clientStarted;
@property (nonatomic, strong) LDThrottler *throttler;
@property (nonatomic, assign) BOOL willGoOnlineAfterDelay;
@end

@implementation LDClient
Expand All @@ -25,6 +29,7 @@ +(LDClient *)sharedInstance
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedLDClient = [[self alloc] init];
sharedLDClient.throttler = [[LDThrottler alloc] initWithMaxDelayInterval:kMaxThrottlingDelayInterval];
[[NSNotificationCenter defaultCenter] addObserver: sharedLDClient
selector:@selector(userUpdated)
name: kLDUserUpdatedNotification object: nil];
Expand Down Expand Up @@ -67,27 +72,25 @@ - (BOOL)start:(LDConfig *)inputConfig withUserBuilder:(LDUserBuilder *)inputUser
inputUserBuilder = inputUserBuilder ?: [[LDUserBuilder alloc] init];
self.ldUser = [inputUserBuilder build];

[LDClientManager sharedInstance].online = YES;
[self setOnline:YES];

return YES;
}

- (BOOL)updateUser:(LDUserBuilder *)builder {
DEBUG_LOGX(@"LDClient updateUser method called");
if (self.clientStarted) {
if (builder) {
self.ldUser = [LDUserBuilder compareNewBuilder:builder withUser:self.ldUser];
LDClientManager *clientManager = [LDClientManager sharedInstance];
[clientManager syncWithServerForConfig];
return YES;
} else {
DEBUG_LOGX(@"LDClient updateUser needs a non-nil LDUserBuilder object");
return NO;
}
} else {
DEBUG_LOGX(@"LDClient not started yet!");
if (!self.clientStarted) {
DEBUG_LOGX(@"LDClient aborted updateUser: client not started");
return NO;
}
if (!builder) {
DEBUG_LOGX(@"LDClient aborted updateUser: LDUserBuilder is nil");
return NO;
}

self.ldUser = [LDUserBuilder compareNewBuilder:builder withUser:self.ldUser];
[[LDClientManager sharedInstance] updateUser];
return YES;
}

- (LDUserBuilder *)currentUserBuilder {
Expand Down Expand Up @@ -241,29 +244,50 @@ - (BOOL)track:(NSString *)eventName data:(NSDictionary *)dataDictionary
}
}

- (BOOL)offline
{
DEBUG_LOGX(@"LDClient offline method called");
if (self.clientStarted) {
LDClientManager *clientManager = [LDClientManager sharedInstance];
[clientManager setOnline:NO];
return YES;
} else {
-(void)setOnline:(BOOL)goOnline {
[self setOnline:goOnline completion:nil];
}

-(void)setOnline:(BOOL)goOnline completion:(void(^)(void))completion {
if (!self.clientStarted) {
DEBUG_LOGX(@"LDClient not started yet!");
return NO;
if (completion) {
completion();
}
return;
}
self.willGoOnlineAfterDelay = goOnline;
if (goOnline == self.isOnline) {
DEBUG_LOG(@"LDClient setOnline:%@ aborted. LDClient is already %@", goOnline ? @"YES" : @"NO", goOnline ? @"online" : @"offline");
if (completion) {
completion();
}
return;
}

if (!goOnline) {
DEBUG_LOGX(@"LDClient setOnline:NO called");
[self _setOnline:NO completion:completion];
return;
}
[self.throttler runThrottled:^{
if (!self.willGoOnlineAfterDelay) {
DEBUG_LOGX(@"LDClient setOnline:YES aborted. Client last received an offline request when the throttling timer expired.");
if (completion) {
completion();
}
return;
}
DEBUG_LOGX(@"LDClient setOnline:YES called");
[self _setOnline:YES completion:completion];
}];
}

- (BOOL)online
{
DEBUG_LOGX(@"LDClient online method called");
if (self.clientStarted) {
LDClientManager *clientManager = [LDClientManager sharedInstance];
[clientManager setOnline:YES];
return YES;
} else {
DEBUG_LOGX(@"LDClient not started yet!");
return NO;
-(void)_setOnline:(BOOL)isOnline completion:(void(^)(void))completion {
self.isOnline = isOnline;
[[LDClientManager sharedInstance] setOnline:isOnline];
if (completion) {
completion();
}
}

Expand All @@ -286,7 +310,7 @@ - (BOOL)stopClient {
return NO;
}

[self offline];
[self setOnline:NO];
self.clientStarted = NO;
return YES;
}
Expand Down Expand Up @@ -327,7 +351,7 @@ -(void)configFlagUpdated:(NSNotification *)notification {
-(void)handleClientUnauthorizedNotification {
[NSThread performOnMainThread:^{
DEBUG_LOGX(@"LDClient received Client Unauthorized notification. Taking LDClient offline.");
[self offline];
[self setOnline:NO];
}];
}

Expand Down
1 change: 1 addition & 0 deletions Darkly/LDClientManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- (void)processedConfig:(BOOL)success jsonConfigDictionary:(NSDictionary *)jsonConfigDictionary;
- (void)startPolling;
- (void)stopPolling;
- (void)updateUser;
- (void)willEnterBackground;
- (void)willEnterForeground;
- (void)flushEvents;
Expand Down
Loading