ObjcLDClient
@objc(LDClient)
public final class ObjcLDClient : NSObject
The LDClient is the heart of the SDK, providing client apps running iOS, watchOS, macOS, or tvOS access to LaunchDarkly services. This singleton provides the ability to set a configuration (LDConfig) that controls how the LDClient talks to LaunchDarkly servers, and a context (LDContext) that provides finer control on the feature flag values delivered to LDClient. Once the LDClient has started, it connects to LaunchDarkly’s servers to get the feature flag values you set in the Dashboard.
Objc Classes
The SDK creates an Objective-C native style API by wrapping Swift specific classes, properties, and methods into Objective-C wrapper classes prefixed by Objc. By defining Objective-C specific names, client apps written in Objective-C can use a native coding style, including using familiar LaunchDarkly SDK names like LDClient, LDConfig, and LDContext. Objective-C developers should refer to the Objc documentation by following the Objc specific links following type, property, and method names.
Usage
Startup
- To customize, configure a LDConfig (
ObjcLDConfig) and LDContext (ObjcLDContxt). Both give you additional control over the feature flags delivered to the LDClient. SeeObjcLDConfig&ObjcLDContextfor more details. - The mobileKey set into the
LDConfigcomes from your LaunchDarkly Account settings (on the left, at the bottom). If you have multiple projects be sure to choose the correct Mobile key. - Call
[ObjcLDClient startWithConfig: context: completion:](ObjcLDClient.startWithConfig(_:config:context:completion:)) - If you do not pass in a LDContext, LDCLient will create a default for you.
- The optional completion closure allows the LDClient to notify your app when it has gone online.
- Because the LDClient is a singleton, you do not have to keep a reference to it in your code.
Getting Feature Flags
Once the LDClient has started, it makes your feature flags available using the variation and variationDetail methods. A variation is a specific flag value. For example, a boolean feature flag has 2 variations, YES and NO. You can create feature flags with more than 2 variations using other feature flag types. See LDValue for the available types.
BOOL boolFlag = [ldClientInstance boolVariationForKey:@"my-bool-flag" defaultValue:NO];
If you need to know more information about why a given value is returned, the typed variationDetail methods return an LD<T>EvaluationDetail with an detail about the evaluation.
LDBoolEvaluationDetail *boolVariationDetail = [ldClientInstance boolVariationDetail:@"my-bool-flag" defaultValue:NO];
BOOL boolFlagValue = boolVariationDetail.value;
NSInteger boolFlagVariation = boolVariationDetail.variationIndex
NSDictionary boolFlagReason = boolVariationValue.reason;
See the typed -[LDCLient variationForKey: defaultValue:] or -[LDClient variationDetailForKey: defaultValue:] methods in the section Feature Flag values for details.
Observing Feature Flags
If you want to know when a feature flag value changes, you can check the flag’s value. You can also use one of several observe methods to have the LDClient notify you when a change occurs. There are several options– you can setup notifications based on when a specific flag changes, when any flag in a collection changes, or when a flag doesn’t change. The flag change listener may be invoked multiple times per invocation of LDClient.identify as the SDK fetches up to date flag data from multiple sources (e.g. local cache, cloud services). In certain error cases, the SDK may not be able to retrieve flag data during an identify (e.g. no network connectivity). In those cases, the flag change listener may not be invoked.
__weak typeof(self) weakSelf = self;
[ldClientInstance observeBool:@"my-bool-flag" owner:self handler:^(LDBoolChangedFlag *changedFlag) {
__strong typeof(weakSelf) strongSelf = weakSelf;
[strongSelf updateFlagWithKey:@"my-bool-flag" changedFlag:changedFlag];
}];
The changedFlag passed in to the block contains the old and new value. See the typed LDChangedFlag classes in the Obj-C Changed Flags.
-
Reports the online/offline state of the LDClient.
When online, the SDK communicates with LaunchDarkly servers for feature flag values and event reporting.
When offline, the SDK does not attempt to communicate with LaunchDarkly servers. Client apps can request feature flag values and set/change feature flag observers while offline. The SDK will collect events while offline.
Use
-[LDClient setOnline: completion:](ObjcLDClient.setOnline(_:completion:)) to change the online/offline state.Declaration
Swift
@objc public var isOnline: Bool { get } -
Set the LDClient online/offline.
When online, the SDK communicates with LaunchDarkly servers for feature flag values and event reporting. When offline, the SDK does not attempt to communicate with LaunchDarkly servers. Client apps can request feature flag values and set/change feature flag observers while offline. The SDK will collect events while offline. The SDK protects itself from multiple rapid calls to
setOnline:YESby enforcing an increasing delay (called throttling) each timesetOnline:YESis called within a short time. The first time, the call proceeds normally. For each subsequent call the delay is enforced, and if waiting, increased to a maximum delay. When the delay has elapsed, thesetOnline:YESwill proceed, assuming that the client app has not calledsetOnline:NOduring the delay. Therefore a call tosetOnline:YESmay not immediately result in the LDClient going online. Client app developers should consider this situation abnormal, and take steps to prevent the client app from making multiple rapidsetOnline:YEScalls. Calls tosetOnline:NOare not throttled. After the delay, the SDK resets and the client app can make a susequent call tosetOnline:YESwithout being throttled. UseisOnlineto get the online/offline state.Declaration
Swift
@objc public func setOnline(_ goOnline: Bool)Parameters
goOnlineDesired online/offline mode for the LDClient
-
Set the LDClient online/offline.
When online, the SDK communicates with LaunchDarkly servers for feature flag values and event reporting.
When offline, the SDK does not attempt to communicate with LaunchDarkly servers. Client apps can request feature flag values and set/change feature flag observers while offline. The SDK will collect events while offline.
The SDK protects itself from multiple rapid calls to
setOnline:YESby enforcing an increasing delay (called throttling) each timesetOnline:YESis called within a short time. The first time, the call proceeds normally. For each subsequent call the delay is enforced, and if waiting, increased to a maximum delay. When the delay has elapsed, thesetOnline:YESwill proceed, assuming that the client app has not calledsetOnline:NOduring the delay. Therefore a call tosetOnline:YESmay not immediately result in the LDClient going online. Client app developers should consider this situation abnormal, and take steps to prevent the client app from making multiple rapidsetOnline:YEScalls. Calls tosetOnline:NOare not throttled. Note that calls tostart(config: context: completion:), and setting theconfigorcontextcan also callsetOnline:YESunder certain conditions. After the delay, the SDK resets and the client app can make a susequent call tosetOnline:YESwithout being throttled.Client apps can set a completion block called when the setOnline call completes. For unthrottled
setOnline:YESand allsetOnline:NOcalls, the SDK will call the block immediately on completion of this method. For throttledsetOnline:YEScalls, the SDK will call the block after the throttling delay at the completion of the setOnline method.Use
isOnline(ObjcLDClient.isOnline)to get the online/offline state.Declaration
Swift
@objc public func setOnline(_ goOnline: Bool, completion: (() -> Void)? = nil)Parameters
goOnlineDesired online/offline mode for the LDClient
completionCompletion block called when setOnline completes. (Optional)
-
Reports the initialization state of the LDClient.
When true, the SDK has either communicated with LaunchDarkly servers for feature flag values or the SDK has been set offline.
When false, the SDK has not been able to communicate with LaunchDarkly servers. Client apps can request feature flag values and set/change feature flag observers but flags might not exist or be stale.
Declaration
Swift
@objc public var isInitialized: Bool { get } -
The LDContext set into the LDClient may affect the set of feature flags returned by the LaunchDarkly server, and ties event tracking to the context. See
LDContextfor details about what information can be retained.The client app can change the current LDContext by calling this method. Client apps should follow Apple’s Privacy Policy when collecting user information. When a new context is set, the LDClient goes offline and sets the new context. If the client was online when the new context was set, it goes online again, subject to a throttling delay if in force (see
setOnline(_: completion:)for details).Declaration
Swift
@objc public func identify(context: ObjcLDContext)Parameters
contextThe ObjcLDContext set with the desired context.
-
The LDContext set into the LDClient may affect the set of feature flags returned by the LaunchDarkly server, and ties event tracking to the context. See
LDContextfor details about what information can be retained.Normally, the client app should create and set the LDContext and pass that into
start(config: context: completion:).The client app can change the active
contextby calling identify with a new or updated LDContext. Client apps should follow Apple’s Privacy Policy when collecting user information. If the client app does not create a LDContext, LDClient creates an anonymous default context, which can affect the feature flags delivered to the LDClient.When a new context is set, the LDClient goes offline and sets the new context. If the client was online when the new context was set, it goes online again, subject to a throttling delay if in force (see
setOnline(_: completion:)for details). To change both theconfigandcontext, set the LDClient offline, set both properties, then set the LDClient online. A completion may be passed to the identify method to allow a client app to know when fresh flag values for the new context are ready.Declaration
Swift
@objc public func identify(context: ObjcLDContext, completion: (() -> Void)? = nil)Parameters
contextThe ObjcLDContext set with the desired context.
completionClosure called when the embedded
setOnlineIdentifycall completes, subject to throttling delays. (Optional) -
Stops the LDClient. Stopping the client means the LDClient goes offline and stops recording events. LDClient will no longer provide feature flag values, only returning default values.
There is almost no reason to stop the LDClient. Normally, set the LDClient offline to stop communication with the LaunchDarkly servers. Stop the LDClient to stop recording events. There is no need to stop the LDClient prior to suspending, moving to the background, or terminating the app. The SDK will respond to these events as the system requires and as configured in LDConfig.
Declaration
Swift
@objc public func close() -
Returns an ObjcLDClient wrapper that contains the primary LDClient instance.
Declaration
Swift
@objc public static func get() -> ObjcLDClient?Return Value
An ObjcLDClient.
-
Returns an LDClient instance for a given environment.
Declaration
Swift
@objc public static func get(environment: String = LDConfig.Constants.primaryEnvironmentName) -> ObjcLDClient?Parameters
environmentThe name of an environment provided in LDConfig.secondaryMobileKeys, defaults to
LDConfig.Constants.primaryEnvironmentName, which is always associated with theLDConfig.mobileKeyenvironment.Return Value
The requested LDClient instance.
-
Returns the BOOL variation for the given feature flag. If the flag does not exist, cannot be cast to a BOOL, or the LDClient is not started, returns the default value.
A variation is a specific flag value. For example a boolean feature flag has 2 variations, YES and NO. You can create feature flags with more than 2 variations using other feature flag types. See
LDValuefor the available types.A call to
boolVariationrecords events reported later. Recorded events allow clients to analyze usage and assist in debugging issues.Usage
BOOL boolFeatureFlagValue = [ldClientInstance boolVariationForKey:@"my-bool-flag" defaultValue:NO];Declaration
Swift
@objc public func boolVariation(forKey key: LDFlagKey, defaultValue: Bool) -> BoolParameters
keyThe LDFlagKey for the requested feature flag.
defaultValueThe default value to return if the feature flag key does not exist.
Return Value
The requested BOOL feature flag value, or the default value if the flag is missing or cannot be cast to a BOOL, or the client is not started
-
See boolVariation for more information on variation methods.
Declaration
Swift
@objc public func boolVariationDetail(forKey key: LDFlagKey, defaultValue: Bool) -> ObjcLDBoolEvaluationDetailParameters
keyThe LDFlagKey for the requested feature flag.
defaultValueThe default value to return if the feature flag key does not exist.
Return Value
ObjcLDBoolEvaluationDetail containing your value as well as useful information on why that value was returned.
-
Returns the NSInteger variation for the given feature flag. If the flag does not exist, cannot be cast to a NSInteger, or the LDClient is not started, returns the default value.
A variation is a specific flag value. For example a boolean feature flag has 2 variations, YES and NO. You can create feature flags with more than 2 variations using other feature flag types. See
LDValuefor the available types.A call to
integerVariationrecords events reported later. Recorded events allow clients to analyze usage and assist in debugging issues.Usage
NSInteger integerFeatureFlagValue = [ldClientInstance integerVariationForKey:@"my-integer-flag" defaultValue:5];Declaration
Swift
@objc public func integerVariation(forKey key: LDFlagKey, defaultValue: Int) -> IntParameters
keyThe LDFlagKey for the requested feature flag.
defaultValueThe default value to return if the feature flag key does not exist.
Return Value
The requested NSInteger feature flag value, or the default value if the flag is missing or cannot be cast to a NSInteger, or the client is not started
-
See integerVariation for more information on variation methods.
Declaration
Swift
@objc public func integerVariationDetail(forKey key: LDFlagKey, defaultValue: Int) -> ObjcLDIntegerEvaluationDetailParameters
keyThe LDFlagKey for the requested feature flag.
defaultValueThe default value to return if the feature flag key does not exist.
Return Value
ObjcLDIntegerEvaluationDetail containing your value as well as useful information on why that value was returned.
-
Returns the double variation for the given feature flag. If the flag does not exist, cannot be cast to a double, or the LDClient is not started, returns the default value.
A variation is a specific flag value. For example a boolean feature flag has 2 variations, YES and NO. You can create feature flags with more than 2 variations using other feature flag types. See
LDValuefor the available types.A call to
doubleVariationrecords events reported later. Recorded events allow clients to analyze usage and assist in debugging issues.Usage
double doubleFeatureFlagValue = [ldClientInstance doubleVariationForKey:@"my-double-flag" defaultValue:2.71828];Declaration
Swift
@objc public func doubleVariation(forKey key: LDFlagKey, defaultValue: Double) -> DoubleParameters
keyThe LDFlagKey for the requested feature flag.
defaultValueThe default value to return if the feature flag key does not exist.
Return Value
The requested double feature flag value, or the default value if the flag is missing or cannot be cast to a double, or the client is not started
-
See doubleVariation for more information on variation methods.
Declaration
Swift
@objc public func doubleVariationDetail(forKey key: LDFlagKey, defaultValue: Double) -> ObjcLDDoubleEvaluationDetailParameters
keyThe LDFlagKey for the requested feature flag.
defaultValueThe default value to return if the feature flag key does not exist.
Return Value
ObjcLDDoubleEvaluationDetail containing your value as well as useful information on why that value was returned.
-
Returns the NSString variation for the given feature flag. If the flag does not exist, cannot be cast to a NSString, or the LDClient is not started, returns the default value.
A variation is a specific flag value. For example a boolean feature flag has 2 variations, YES and NO. You can create feature flags with more than 2 variations using other feature flag types. See
LDValuefor the available types.A call to
stringVariationrecords events reported later. Recorded events allow clients to analyze usage and assist in debugging issues.Usage
NSString *stringFeatureFlagValue = [ldClientInstance stringVariationForKey:@"my-string-flag" defaultValue:@"<defaultValue>"];Declaration
Swift
@objc public func stringVariation(forKey key: LDFlagKey, defaultValue: String) -> StringParameters
keyThe LDFlagKey for the requested feature flag.
defaultValueThe default value to return if the feature flag key does not exist.
Return Value
The requested NSString feature flag value, or the default value if the flag is missing or cannot be cast to a NSString, or the client is not started.
-
See stringVariation for more information on variation methods.
Declaration
Swift
@objc public func stringVariationDetail(forKey key: LDFlagKey, defaultValue: String) -> ObjcLDStringEvaluationDetailParameters
keyThe LDFlagKey for the requested feature flag.
defaultValueThe default value to return if the feature flag key does not exist.
Return Value
ObjcLDStringEvaluationDetail containing your value as well as useful information on why that value was returned.
-
Returns the JSON variation for the given feature flag. If the flag does not exist, or the LDClient is not started, returns the default value.
A call to
jsonVariationrecords events reported later. Recorded events allow clients to analyze usage and assist in debugging issues.Usage
ObjcLDValue *featureFlagValue = [ldClientInstance jsonVariationForKey:@"my-flag" defaultValue:[LDValue ofBool:NO]];Declaration
Swift
@objc public func jsonVariation(forKey key: LDFlagKey, defaultValue: ObjcLDValue) -> ObjcLDValueParameters
keyThe LDFlagKey for the requested feature flag.
defaultValueThe default value to return if the feature flag key does not exist.
Return Value
The requested feature flag value, or the default value if the flag is missing or the client is not started
-
See arrayVariation for more information on variation methods.
Declaration
Swift
@objc public func jsonVariationDetail(forKey key: LDFlagKey, defaultValue: ObjcLDValue) -> ObjcLDJSONEvaluationDetailParameters
keyThe LDFlagKey for the requested feature flag.
defaultValueThe default value to return if the feature flag key does not exist.
Return Value
ObjcLDJSONEvaluationDetail containing your value as well as useful information on why that value was returned.
-
Returns a dictionary with the flag keys and their values. If the LDClient is not started, returns nil.
The dictionary will not contain feature flags from the server with null values.
LDClient will not provide any source or change information, only flag keys and flag values. The client app should convert the feature flag value into the desired type.
Declaration
Swift
@objc public var allFlags: [LDFlagKey : ObjcLDValue]? { get }
-
Sets a handler for the specified BOOL flag key executed on the specified owner. If the flag’s value changes, executes the handler, passing in the
changedFlagcontaining the old and new flag values. SeeObjcLDBoolChangedFlagfor details.The SDK retains only weak references to the owner, which allows the client app to freely destroy owners without issues. Client apps should capture a strong self reference from a weak reference immediately inside the handler to avoid retain cycles causing a memory leak.
The SDK executes handlers on the main thread.
SeeAlso:
ObjcLDBoolChangedFlagandstopObserving(owner:)Usage
__weak typeof(self) weakSelf = self; [ldClientInstance observeBool:"my-bool-flag" owner:self handler:^(LDBoolChangedFlag *changedFlag){ __strong typeof(weakSelf) strongSelf = weakSelf; [strongSelf showBoolChangedFlag:changedFlag]; }];Declaration
Swift
@objc public func observe(_ key: LDFlagKey, owner: LDObserverOwner, handler: @escaping ObjcLDChangedFlagHandler)Parameters
keyThe LDFlagKey for the flag to observe.
ownerThe LDFlagChangeOwner which will execute the handler. The SDK retains a weak reference to the owner.
handlerThe block the SDK will execute when the feature flag changes.
-
Sets a handler for the specified flag keys executed on the specified owner. If any observed flag’s value changes, executes the handler 1 time, passing in a dictionary of
containing the old and new flag values. See LDChangedFlag ( ObjcLDChangedFlag) for details.The SDK retains only weak references to owner, which allows the client app to freely destroy change owners without issues. Client apps should capture a strong self reference from a weak reference immediately inside the handler to avoid retain cycles causing a memory leak.
The SDK executes handlers on the main thread.
SeeAlso:
ObjcLDChangedFlagandstopObserving(owner:)Usage
__weak typeof(self) weakSelf = self; [ldClientInstance observeKeys:@[@"my-bool-flag",@"my-string-flag", @"my-dictionary-flag"] owner:self handler:^(NSDictionary<NSString *,LDChangedFlag *> * _Nonnull changedFlags) { __strong typeof(weakSelf) strongSelf = weakSelf; //There will be a typed LDChangedFlag entry in changedFlags for each changed flag. The block will only be called once regardless of how many flags changed. [strongSelf showChangedFlags: changedFlags]; }];Declaration
Swift
@objc public func observeKeys(_ keys: [LDFlagKey], owner: LDObserverOwner, handler: @escaping ObjcLDChangedFlagCollectionHandler)Parameters
keysAn array of NSString* flag keys for the flags to observe.
ownerThe LDFlagChangeOwner which will execute the handler. The SDK retains a weak reference to the owner.
handlerThe LDFlagCollectionChangeHandler the SDK will execute 1 time when any of the observed feature flags change.
-
Sets a handler for all flag keys executed on the specified owner. If any flag’s value changes, executes the handler 1 time, passing in a dictionary of
containing the old and new flag values. See LDChangedFlag ( ObjcLDChangedFlag) for details.The SDK retains only weak references to owner, which allows the client app to freely destroy change owners without issues. Client apps should capture a strong self reference from a weak reference immediately inside the handler to avoid retain cycles causing a memory leak.
The SDK executes handlers on the main thread.
SeeAlso:
ObjcLDChangedFlagandstopObserving(owner:)Usage
__weak typeof(self) weakSelf = self; [ldClientInstance observeAllKeysWithOwner:self handler:^(NSDictionary<NSString *,LDChangedFlag *> * _Nonnull changedFlags) { __strong typeof(weakSelf) strongSelf = weakSelf; //There will be a typed LDChangedFlag entry in changedFlags for each changed flag. The block will only be called once regardless of how many flags changed. [strongSelf showChangedFlags:changedFlags]; }];Declaration
Swift
@objc public func observeAllKeys(owner: LDObserverOwner, handler: @escaping ObjcLDChangedFlagCollectionHandler)Parameters
ownerThe LDFlagChangeOwner which will execute the handler. The SDK retains a weak reference to the owner.
handlerThe LDFlagCollectionChangeHandler the SDK will execute 1 time when any of the observed feature flags change.
-
Sets a handler executed when a flag update leaves the flags unchanged from their previous values.
This handler can only ever be called when the LDClient is polling.
The SDK retains only weak references to owner, which allows the client app to freely destroy change owners without issues. Client apps should capture a strong self reference from a weak reference immediately inside the handler to avoid retain cycles causing a memory leak.
The SDK executes handlers on the main thread.
SeeAlso:
stopObserving(owner:)Usage
__weak typeof(self) weakSelf = self; [[LDClient sharedInstance] observeFlagsUnchangedWithOwner:self handler:^{ __strong typeof(weakSelf) strongSelf = weakSelf; //do something after the flags were not updated. The block will be called once on the main thread if the client is polling and the poll did not change any flag values. [self checkFeatureValues]; }];Declaration
Swift
@objc public func observeFlagsUnchanged(owner: LDObserverOwner, handler: @escaping LDFlagsUnchangedHandler)Parameters
ownerThe LDFlagChangeOwner which will execute the handler. The SDK retains a weak reference to the owner.
handlerThe LDFlagsUnchangedHandler the SDK will execute 1 time when a flag request completes with no flags changed.
-
Removes all observers for the given owner, including a flagsUnchangedObserver
The client app does not have to call this method. If the client app deinits a LDFlagChangeOwner, the SDK will automatically remove its handlers without ever calling them again.
Declaration
Swift
@objc(stopObservingForOwner:) public func stopObserving(owner: LDObserverOwner)Parameters
ownerThe LDFlagChangeOwner owning the handlers to remove, whether a flag change handler or flags unchanged handler.
-
Handler passed to the client app when a feature flag value changes
Declaration
Swift
public typealias ObjcLDChangedFlagHandler = (_ changedFlag: ObjcLDChangedFlag) -> VoidParameters
changedFlagThe LDChangedFlag passed into the handler containing the old & new flag value
-
Handler passed to the client app when a NSArray feature flag value changes
Declaration
Swift
public typealias ObjcLDChangedFlagCollectionHandler = (_ changedFlags: [LDFlagKey : ObjcLDChangedFlag]) -> VoidParameters
changedFlagsA dictionary
using the changed flag keys as the dictionary keys. Cast the resulting LDChangedFlag to the correct LDChangedFlagType.
-
Adds a custom event to the LDClient event store. A client app can set a tracking event to allow client customized data analysis. Once an app has called
track, the app cannot remove the event from the event store.LDClient periodically transmits events to LaunchDarkly based on the frequency set in LDConfig.eventFlushInterval. The LDClient must be started and online. Ths SDK stores events tracked while the LDClient is offline, but started.
Once the SDK’s event store is full, the SDK discards events until they can be reported to LaunchDarkly. Configure the size of the event store using
eventCapacityon theconfig. SeeLDConfig(ObjcLDConfig) for details.Usage
[ldClientInstance trackWithKey:@"event-key" data:@{@"event-data-key":7}];Declaration
Swift
@objc public func track(key: String, data: ObjcLDValue? = nil)Parameters
keyThe key for the event. The SDK does nothing with the key, which can be any string the client app sends
dataThe data for the event. The SDK does nothing with the data, which can be any valid JSON item the client app sends. (Optional)
errorNSError object to hold the invalidJsonObject error if the data is not a valid JSON item. (Optional)
-
See (track)[x-source-tag://track] for full documentation.
Declaration
Swift
@objc public func track(key: String, data: ObjcLDValue? = nil, metricValue: Double)Parameters
keyThe key for the event. The SDK does nothing with the key, which can be any string the client app sends
dataThe data for the event. The SDK does nothing with the data, which can be any valid JSON item the client app sends. (Optional)
metricValueA numeric value used by the LaunchDarkly experimentation feature in numeric custom metrics. Can be omitted if this event is used by only non-numeric metrics. This field will also be returned as part of the custom event for Data Export.
errorNSError object to hold the invalidJsonObject error if the data is not a valid JSON item. (Optional)
-
Tells the SDK to immediately send any currently queued events to LaunchDarkly.
There should not normally be a need to call this function. While online, the LDClient automatically reports events on an interval defined by
LDConfig.eventFlushInterval. Note that this function does not block until events are sent, it only triggers a background task to send events immediately.Declaration
Swift
@objc public func flush() -
Starts the LDClient using the passed in
config&context. Call this before requesting feature flag values. The LDClient will not go online until you call this method. Starting the LDClient means setting theconfig&context, setting the client online ifconfig.startOnlineis true (the default setting), and starting event recording. The client app must start the LDClient before it will report feature flag values. If a client does not callstart, no methods will work. If thestartcall omits thecontext, the LDClient uses the defaultcontextif it was never set. If thestartcall includes the optionalcompletionclosure, LDClient calls thecompletionclosure whensetOnline(_: completion:)embedded in theinitmethod completes. This method listens for flag updates so the completion will only return once an update has occurred. Thestartcall is subject to throttling delays, therefore thecompletionclosure call may be delayed. Subsequent calls to this method cause the LDClient to return. Normally there should only be one call to start. To changecontext, useidentify.Declaration
Swift
@objc public static func start(configuration: ObjcLDConfig, context: ObjcLDContext, completion: (() -> Void)? = nil)Parameters
configurationThe LDConfig that contains the desired configuration. (Required)
contextThe LDContext set with the desired context. If omitted, LDClient sets a default context. (Optional)
completionClosure called when the embedded
setOnlinecall completes. (Optional) -
See start for more information on starting the SDK.
Declaration
Swift
@objc public static func start(configuration: ObjcLDConfig, context: ObjcLDContext, startWaitSeconds: TimeInterval, completion: ((_ timedOut: Bool) -> Void)? = nil)Parameters
configurationThe LDConfig that contains the desired configuration. (Required)
contextThe LDContext set with the desired context. If omitted, LDClient sets a default context.. (Optional)
startWaitSecondsA TimeInterval that determines when the completion will return if no flags have been returned from the network.
completionClosure called when the embedded
setOnlinecall completes. Takes a Bool that indicates whether the completion timedout as a parameter. (Optional)
View on GitHub