Launch Darkly
Tested with Launch Darkly version 9.12.0 (iOS)
Last updated
import Foundation
import AppfigurateLibrary
@objcMembers class MyConfiguration: APLConfiguration {
...
@RemoteBoolProperty(key: "alwaysDarkMode", description: "Force dark mode to be always set")
var alwaysDarkMode: Bool
@RemoteStringPropertyEdit(key: "appTitle", description: "Title of application")
var appTitle: String
@RemoteIntPropertyEdit(key: "bookingDuration", description: "Duration (days) for reservation bookings")
var bookingDuration: Int
@RemoteDoublePropertyEdit(key: "fontSize", description: "Size of font throughout app")
var fontSize: Double
...
override func reset() {
alwaysDarkMode = false
appTitle = "Holiday finder"
bookingDuration = 30
fontSize = 13.0
}
...
}@import Foundation;
@import AppfigurateLibrary;
@interface MyConfiguration : APLConfiguration
...
@property(nonatomic, assign) BOOL alwaysDarkMode;
@property(nonatomic, strong) NSString* appTitle;
@property(nonatomic, assign) NSInteger bookingDuration;
@property(nonatomic, assign) double fontSize;
...
@end
#import "MyConfiguration.h"
@implementation MyConfiguration
...
REMOTE_BOOL_PROPERTY(alwaysDarkMode, @"alwaysDarkMode", @"Force dark mode to be always set");
REMOTE_STRING_PROPERTY_EDIT(appTitle, @"appTitle", @"Title of application");
REMOTE_INT_PROPERTY_EDIT(bookingDuration, @"bookingDuration", @"Duration (days) for reservation bookings");
REMOTE_DOUBLE_PROPERTY_EDIT(fontSize, @"fontSize", @"Size of font throughout app");
...
- (void) reset {
self.alwaysDarkMode = NO;
self.appTitle = @"Holiday finder";
self.bookingDuration = 30;
self.fontSize = 13.0;
}
...
@endAPLFetchRemoteConfiguration { propertyKey, propertyType, defaultValue in
if propertyType == .bool {
return NSNumber(value: (LDClient.get()!.boolVariation(forKey: propertyKey, defaultValue: (defaultValue as! NSNumber).boolValue)))
} else if propertyType == .int {
return NSNumber(value: (LDClient.get()!.intVariation(forKey: propertyKey, defaultValue: (defaultValue as! NSNumber).intValue)))
} else if propertyType == .double {
return NSNumber(value: (LDClient.get()!.doubleVariation(forKey: propertyKey, defaultValue: (defaultValue as! NSNumber).doubleValue)))
} else { // .string
return NSString(string: LDClient.get()!.stringVariation(forKey: propertyKey, defaultValue: (defaultValue as! String)))
}
}APLFetchRemoteConfiguration(^NSObject* (NSString* propertyKey, APLRemotePropertyType propertyType, NSObject* defaultValue) {
if (propertyType == APLRemotePropertyTypeBool) {
return [NSNumber numberWithBool: [[LDClient get] boolVariationForKey: propertyKey defaultValue: [((NSNumber*) defaultValue) boolValue]]];
} else if (propertyType == APLRemotePropertyTypeInt) {
return [NSNumber numberWithInteger: [[LDClient get] integerVariationForKey: propertyKey defaultValue: [((NSNumber*) defaultValue) integerValue]]];
} else if (propertyType == APLRemotePropertyTypeDouble) {
return [NSNumber numberWithDouble: [[LDClient get] doubleVariationForKey: propertyKey defaultValue: [((NSNumber*) defaultValue) doubleValue]]];
} else { // APLRemotePropertyTypeString
return [[LDClient get] stringVariationForKey: propertyKey defaultValue: (NSString*) defaultValue];
}
});LDClient.start(config: config, startWaitSeconds: 5.0) { timedOut in
...
APLFlushRemoteConfiguration() // add this line
}
...
LDClient.get()?.observeAll(owner: self) { keys in
...
APLFlushRemoteConfiguration() // add this line
}[LDClient startWithConfiguration:config startWaitSeconds:5.0 completion:^(bool timedOut) {
...
APLFlushRemoteConfiguration(); // add this line
}];
...
[[LDClient get] observeAllKeysWithOwner: self handler:^(NSDictionary<NSString *,LDChangedFlag *> *handler) {
...
APLFlushRemoteConfiguration(); // add this line
}];let config = LDConfig(mobileKey: "<YOUR-KEY>", autoEnvAttributes: .enabled)
// add this block of code
APLFetchRemoteConfiguration { propertyKey, propertyType, defaultValue in
if propertyType == .bool {
return NSNumber(value: (LDClient.get()!.boolVariation(forKey: propertyKey, defaultValue: (defaultValue as! NSNumber).boolValue)))
} else if propertyType == .int {
return NSNumber(value: (LDClient.get()!.intVariation(forKey: propertyKey, defaultValue: (defaultValue as! NSNumber).intValue)))
} else if propertyType == .double {
return NSNumber(value: (LDClient.get()!.doubleVariation(forKey: propertyKey, defaultValue: (defaultValue as! NSNumber).doubleValue)))
} else {
return NSString(string: LDClient.get()!.stringVariation(forKey: propertyKey, defaultValue: (defaultValue as! String)))
}
}
LDClient.start(config: config, startWaitSeconds: 5.0) { timedOut in
if !timedOut {
APLFlushRemoteConfiguration() // add this line
}
}
LDClient.get()?.observeAll(owner: self) { keys in
APLFlushRemoteConfiguration() // add this line
}LDConfig* config = [[LDConfig alloc] initWithMobileKey: @"<YOUR-KEY>" autoEnvAttributes:AutoEnvAttributesEnabled];
// add this block of code
APLFetchRemoteConfiguration(^NSObject* (NSString* propertyKey, APLRemotePropertyType propertyType, NSObject* defaultValue) {
if (propertyType == APLRemotePropertyTypeBool) {
return [NSNumber numberWithBool: [[LDClient get] boolVariationForKey: propertyKey defaultValue: [((NSNumber*) defaultValue) boolValue]]];
} else if (propertyType == APLRemotePropertyTypeInt) {
return [NSNumber numberWithInteger: [[LDClient get] integerVariationForKey: propertyKey defaultValue: [((NSNumber*) defaultValue) integerValue]]];
} else if (propertyType == APLRemotePropertyTypeDouble) {
return [NSNumber numberWithDouble: [[LDClient get] doubleVariationForKey: propertyKey defaultValue: [((NSNumber*) defaultValue) doubleValue]]];
} else {
return [[LDClient get] stringVariationForKey: propertyKey defaultValue: (NSString*) defaultValue];
}
});
LDContext* context = [[[[LDContextBuilder alloc] initWithKey: @"<YOUR-CONTEXT>"] build] success];
[LDClient startWithConfiguration:config context:context startWaitSeconds:5.0 completion:^(bool timedOut) {
if (!timedOut) {
APLFlushRemoteConfiguration(); // add this line
}
}];
[[LDClient get] observeAllKeysWithOwner: self handler: ^(NSDictionary<NSString *,LDChangedFlag *> *handler) {
APLFlushRemoteConfiguration(); // add this line
}];if (LDClient.get()!.boolVariation(forKey: "alwaysDarkMode", defaultValue: false)) {
...if (CONFIGURATION().alwaysDarkMode) {
...if ([[LDClient get] boolVariationForKey: @"alwaysDarkMode" defaultValue: NO]) {
...if (CONFIGURATION.alwaysDarkMode) {
...