diff --git a/internal/sdks/sdk_instructions/android.md b/internal/sdks/sdk_instructions/android.md
index b757b301..561f3052 100644
--- a/internal/sdks/sdk_instructions/android.md
+++ b/internal/sdks/sdk_instructions/android.md
@@ -11,41 +11,66 @@ dependencies {
3. Open the file `MainActivity.kt` and add the following code:
```java
+package com.launchdarkly.hello_android
+
+import android.os.Bundle
+import android.view.View
+import android.widget.TextView
+import androidx.appcompat.app.AlertDialog
+import androidx.appcompat.app.AppCompatActivity
+import com.launchdarkly.hello_android.MainApplication.Companion.LAUNCHDARKLY_MOBILE_KEY
import com.launchdarkly.sdk.android.LDClient
class MainActivity : AppCompatActivity() {
- // Set BOOLEAN_FLAG_KEY to the boolean feature flag you want to evaluate.
- val BOOLEAN_FLAG_KEY = "my-flag-key"
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_main)
- val textView : TextView = findViewById(R.id.textview)
-
- val client = LDClient.get()
-
- // to get the variation the SDK has cached
- textView.text = getString(
- R.string.flag_evaluated,
- BOOLEAN_FLAG_KEY,
- client.boolVariation(BOOLEAN_FLAG_KEY, false).toString()
- )
-
- // to register a listener to get updates in real time
- client.registerFeatureFlagListener(BOOLEAN_FLAG_KEY) {
- textView.text = getString(
- R.string.flag_evaluated,
- BOOLEAN_FLAG_KEY,
- client.boolVariation(BOOLEAN_FLAG_KEY, false).toString()
- )
- }
-
- // This call ensures all evaluation events show up immediately for this demo. Otherwise, the
- // SDK sends them at some point in the future. You don't need to call this in production,
- // because the SDK handles them automatically at an interval. The interval is customizable.
- client.flush()
- }
+ // Set BOOLEAN_FLAG_KEY to the feature flag key you want to evaluate.
+ val BOOLEAN_FLAG_KEY = "my-flag-key"
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_main)
+ val textView : TextView = findViewById(R.id.textview)
+ val fullView : View = window.decorView
+
+ if (LAUNCHDARKLY_MOBILE_KEY == "example-mobile-key") {
+ val builder = AlertDialog.Builder(this)
+ builder.setMessage("LAUNCHDARKLY_MOBILE_KEY was not customized for this application.")
+ builder.create().show()
+ }
+
+ val client = LDClient.get()
+ val flagValue = client.boolVariation(BOOLEAN_FLAG_KEY, false)
+
+ // to get the variation the SDK has cached
+ textView.text = getString(
+ R.string.flag_evaluated,
+ BOOLEAN_FLAG_KEY,
+ flagValue.toString()
+ )
+
+ // Style the display
+ textView.setTextColor(resources.getColor(R.color.colorText))
+ if(flagValue) {
+ fullView.setBackgroundColor(resources.getColor(R.color.colorBackgroundTrue))
+ } else {
+ fullView.setBackgroundColor(resources.getColor(R.color.colorBackgroundFalse))
+ }
+
+ // to register a listener to get updates in real time
+ client.registerFeatureFlagListener(BOOLEAN_FLAG_KEY) {
+ val changedFlagValue = client.boolVariation(BOOLEAN_FLAG_KEY, false)
+ textView.text = getString(
+ R.string.flag_evaluated,
+ BOOLEAN_FLAG_KEY,
+ changedFlagValue.toString()
+ )
+ if(changedFlagValue) {
+ fullView.setBackgroundColor(resources.getColor(R.color.colorBackgroundTrue))
+ } else {
+ fullView.setBackgroundColor(resources.getColor(R.color.colorBackgroundFalse))
+ }
+ }
+ }
}
```
@@ -60,47 +85,54 @@ class MainActivity : AppCompatActivity() {
5. Create `MainApplication.kt` and add the following code:
```java
+package com.launchdarkly.hello_android
+
+import android.app.Application
import com.launchdarkly.sdk.ContextKind
import com.launchdarkly.sdk.LDContext
import com.launchdarkly.sdk.android.LDClient
import com.launchdarkly.sdk.android.LDConfig
+import com.launchdarkly.sdk.android.LDConfig.Builder.AutoEnvAttributes
class MainApplication : Application() {
- companion object {
-
- // Set LAUNCHDARKLY_MOBILE_KEY to your LaunchDarkly SDK mobile key.
- const val LAUNCHDARKLY_MOBILE_KEY = "myMobileKey"
- }
+ companion object {
- override fun onCreate() {
- super.onCreate()
+ // Set LAUNCHDARKLY_MOBILE_KEY to your LaunchDarkly SDK mobile key.
+ const val LAUNCHDARKLY_MOBILE_KEY = "myMobileKey"
+ }
- val ldConfig = LDConfig.Builder(AutoEnvAttributes.Enabled)
- .mobileKey(LAUNCHDARKLY_MOBILE_KEY)
- .build()
+ override fun onCreate() {
+ super.onCreate()
- // Set up the context properties. This context should appear on your LaunchDarkly contexts
- // list soon after you run the demo.
- val context = if (isUserLoggedIn()) {
- LDContext.builder(ContextKind.DEFAULT, getUserKey())
- .name(getUserName())
- .build()
- } else {
- LDContext.builder(ContextKind.DEFAULT, "example-user-key")
- .anonymous(true)
- .build()
- }
+ // Set LAUNCHDARKLY_MOBILE_KEY to your LaunchDarkly mobile key found on the LaunchDarkly
+ // dashboard in the start guide.
+ // If you want to disable the Auto EnvironmentAttributes functionality.
+ // Use AutoEnvAttributes.Disabled as the argument to the Builder
+ val ldConfig = LDConfig.Builder(AutoEnvAttributes.Enabled)
+ .mobileKey(LAUNCHDARKLY_MOBILE_KEY)
+ .build()
- LDClient.init(this@MainApplication, ldConfig, context)
- }
+ // Set up the context properties. This context should appear on your LaunchDarkly context
+ // dashboard soon after you run the demo.
+ val context = if (isUserLoggedIn()) {
+ LDContext.builder(ContextKind.DEFAULT, getUserKey())
+ .name(getUserName())
+ .build()
+ } else {
+ LDContext.builder(ContextKind.DEFAULT, "example-user-key")
+ .anonymous(true)
+ .build()
+ }
- private fun isUserLoggedIn(): Boolean = false
+ LDClient.init(this@MainApplication, ldConfig, context)
+ }
- private fun getUserKey(): String = "user-key-123abc"
+ private fun isUserLoggedIn(): Boolean = false
- private fun getUserName(): String = "Sandy"
+ private fun getUserKey(): String = "example-user-key"
+ private fun getUserName(): String = "Sandy"
}
```
diff --git a/internal/sdks/sdk_instructions/dotnet-server.md b/internal/sdks/sdk_instructions/dotnet-server.md
index 45a8efc5..ccf7b494 100644
--- a/internal/sdks/sdk_instructions/dotnet-server.md
+++ b/internal/sdks/sdk_instructions/dotnet-server.md
@@ -9,60 +9,98 @@ Install-Package LaunchDarkly.ServerSdk
3. Open the file `Program.cs` and add the following code:
```cs
using System;
- using LaunchDarkly.Sdk;
- using LaunchDarkly.Sdk.Server;
+using System.Threading.Tasks;
+using LaunchDarkly.Sdk;
+using LaunchDarkly.Sdk.Server;
- namespace HelloDotNet
+namespace HelloDotNet
+{
+ class Hello
{
- class Program
+ public static void ShowBanner(){
+ Console.WriteLine(
+@" ██
+ ██
+ ████████
+ ███████
+██ LAUNCHDARKLY █
+ ███████
+ ████████
+ ██
+ ██
+");
+ }
+
+ static void Main(string[] args)
{
- // Set SdkKey to your LaunchDarkly SDK key.
- public const string SdkKey = "1234567890abcdef";
+ bool CI = Environment.GetEnvironmentVariable("CI") != null;
+
+ string SdkKey = Environment.GetEnvironmentVariable("LAUNCHDARKLY_SDK_KEY");
// Set FeatureFlagKey to the feature flag key you want to evaluate.
- public const string FeatureFlagKey = "my-flag-key";
+ string FeatureFlagKey = "my-flag-key";
- private static void ShowMessage(string s) {
- Console.WriteLine("*** " + s);
- Console.WriteLine();
+ if (string.IsNullOrEmpty(SdkKey))
+ {
+ Console.WriteLine("*** Please set LAUNCHDARKLY_SDK_KEY environment variable to your LaunchDarkly SDK key first\n");
+ Environment.Exit(1);
}
- static void Main(string[] args)
- {
- var ldConfig = Configuration.Default(SdkKey);
+ var ldConfig = Configuration.Default(SdkKey);
- var client = new LdClient(ldConfig);
+ var client = new LdClient(ldConfig);
- if (client.Initialized)
- {
- ShowMessage("SDK successfully initialized!");
- }
- else
- {
- ShowMessage("SDK failed to initialize");
- Environment.Exit(1);
- }
+ if (client.Initialized)
+ {
+ Console.WriteLine("*** SDK successfully initialized!\n");
+ }
+ else
+ {
+ Console.WriteLine("*** SDK failed to initialize\n");
+ Environment.Exit(1);
+ }
- // Set up the evaluation context. This context should appear on your LaunchDarkly contexts
- // dashboard soon after you run the demo.
- var context = Context.Builder("example-user-key")
- .Name("Sandy")
- .Build();
+ // Set up the evaluation context. This context should appear on your LaunchDarkly contexts
+ // dashboard soon after you run the demo.
+ var context = Context.Builder("example-user-key")
+ .Name("Sandy")
+ .Build();
- var flagValue = client.BoolVariation(FeatureFlagKey, context, false);
+ if (Environment.GetEnvironmentVariable("LAUNCHDARKLY_FLAG_KEY") != null)
+ {
+ FeatureFlagKey = Environment.GetEnvironmentVariable("LAUNCHDARKLY_FLAG_KEY");
+ }
+
+ var flagValue = client.BoolVariation(FeatureFlagKey, context, false);
- ShowMessage(string.Format("Feature flag '{0}' is {1}",
- FeatureFlagKey, flagValue));
+ Console.WriteLine(string.Format("*** The {0} feature flag evaluates to {1}.\n",
+ FeatureFlagKey, flagValue));
- // Here we ensure that the SDK shuts down cleanly and has a chance to deliver analytics
- // events to LaunchDarkly before the program exits. If analytics events are not delivered,
- // the context attributes and flag usage statistics will not appear on your dashboard. In
- // a normal long-running application, the SDK would continue running and events would be
- // delivered automatically in the background.
- client.Dispose();
+ if (flagValue)
+ {
+ ShowBanner();
}
+
+ client.FlagTracker.FlagChanged += client.FlagTracker.FlagValueChangeHandler(
+ FeatureFlagKey,
+ context,
+ (sender, changeArgs) => {
+ Console.WriteLine(string.Format("*** The {0} feature flag evaluates to {1}.\n",
+ FeatureFlagKey, changeArgs.NewValue));
+
+ if (changeArgs.NewValue.AsBool) ShowBanner();
+ }
+ );
+
+ if(CI) Environment.Exit(0);
+
+ Console.WriteLine("*** Waiting for changes \n");
+
+ Task waitForever = new Task(() => {});
+ waitForever.Wait();
}
}
+}
```
Now that your application is ready, run the application to see what value we get.
diff --git a/internal/sdks/sdk_instructions/go.md b/internal/sdks/sdk_instructions/go.md
index 1e515f55..7a798052 100644
--- a/internal/sdks/sdk_instructions/go.md
+++ b/internal/sdks/sdk_instructions/go.md
@@ -17,52 +17,84 @@ go get github.com/launchdarkly/go-server-sdk/v6
4. Create a file called main.go and add the following code:
```go
package main
- import (
- "fmt"
- "os"
- "time"
- "github.com/launchdarkly/go-sdk-common/v3/ldcontext"
- ld "github.com/launchdarkly/go-server-sdk/v6"
- )
+import (
+ "fmt"
+ "os"
+ "time"
- // Set sdkKey to your LaunchDarkly SDK key.
- const sdkKey = "1234567890abcdef"
+ "github.com/launchdarkly/go-sdk-common/v3/ldcontext"
+ "github.com/launchdarkly/go-sdk-common/v3/ldvalue"
+ ld "github.com/launchdarkly/go-server-sdk/v7"
+)
+
+func showBanner() {
+ fmt.Print("\n ██ \n" +
+ " ██ \n" +
+ " ████████ \n" +
+ " ███████ \n" +
+ "██ LAUNCHDARKLY █\n" +
+ " ███████ \n" +
+ " ████████ \n" +
+ " ██ \n" +
+ " ██ \n")
+}
+
+func showMessage(s string) { fmt.Printf("*** %%s\n\n", s) }
+
+func main() {
+ var sdkKey = os.Getenv("LAUNCHDARKLY_SDK_KEY")
+
+ if sdkKey == "" {
+ showMessage("LaunchDarkly SDK key is required: set the LAUNCHDARKLY_SDK_KEY environment variable and try again.")
+ os.Exit(1)
+ }
+
+ ldClient, _ := ld.MakeClient(sdkKey, 5*time.Second)
+ if ldClient.Initialized() {
+ showMessage("SDK successfully initialized!")
+ } else {
+ showMessage("SDK failed to initialize")
+ os.Exit(1)
+ }
+
+ // Set up the evaluation context. This context should appear on your LaunchDarkly contexts dashboard
+ // soon after you run the demo.
+ context := ldcontext.NewBuilder("example-user-key").
+ Name("Sandy").
+ Build()
// Set featureFlagKey to the feature flag key you want to evaluate.
- const featureFlagKey = "my-flag-key"
+ var featureFlagKey = "my-flag-key"
- func showMessage(s string) { fmt.Printf("*** %%s\n\n", s) }
+ if os.Getenv("LAUNCHDARKLY_FLAG_KEY") != "" {
+ featureFlagKey = os.Getenv("LAUNCHDARKLY_FLAG_KEY")
+ }
- func main() {
- ldClient, _ := ld.MakeClient(sdkKey, 5*time.Second)
- if ldClient.Initialized() {
- showMessage("SDK successfully initialized!")
- } else {
- showMessage("SDK failed to initialize")
- os.Exit(1)
- }
+ flagValue, err := ldClient.BoolVariation(featureFlagKey, context, false)
+ if err != nil {
+ showMessage("error: " + err.Error())
+ }
- // Set up the evaluation context. This context should appear on your LaunchDarkly contexts dashboard
- // soon after you run the demo.
- context := ldcontext.NewBuilder("example-user-key").
- Name("Sandy").
- Build()
+ showMessage(fmt.Sprintf("The '%%s' feature flag evaluates to %%t.", featureFlagKey, flagValue))
- flagValue, err := ldClient.BoolVariation(featureFlagKey, context, false)
- if err != nil {
- showMessage("error: " + err.Error())
- }
+ if flagValue {
+ showBanner()
+ }
+
+ if os.Getenv("CI") != "" {
+ os.Exit(0)
+ }
- showMessage(fmt.Sprintf("Feature flag '%%s' is %%t ", featureFlagKey, flagValue))
+ updateCh := ldClient.GetFlagTracker().AddFlagValueChangeListener(featureFlagKey, context, ldvalue.Null())
- // Here we ensure that the SDK shuts down cleanly and has a chance to deliver analytics
- // events to LaunchDarkly before the program exits. If analytics events are not delivered,
- // the context attributes and flag usage statistics will not appear on your dashboard. In
- // a normal long-running application, the SDK would continue running and events would be
- // delivered automatically in the background.
- ldClient.Close()
+ for event := range updateCh {
+ showMessage(fmt.Sprintf("The '%%s' feature flag evaluates to %%t.", featureFlagKey, event.NewValue.BoolValue()))
+ if event.NewValue.BoolValue() {
+ showBanner()
+ }
}
+}
```
Now that your application is ready, run the application to see what value we get.
diff --git a/internal/sdks/sdk_instructions/haskell-server.md b/internal/sdks/sdk_instructions/haskell-server.md
index e64cefba..94b3982a 100644
--- a/internal/sdks/sdk_instructions/haskell-server.md
+++ b/internal/sdks/sdk_instructions/haskell-server.md
@@ -16,36 +16,87 @@ launchdarkly-server-sdk, text
4. Edit `app/Main.hs` by adding the following code:
```haskell
-{-# LANGUAGE OverloadedStrings #-}
-
+{-# LANGUAGE OverloadedStrings, NumericUnderscores #-}
module Main where
-
--- Import helper libraries.
import Control.Concurrent (threadDelay)
import Control.Monad (forever)
+import Data.Text (Text, pack)
+import Data.Function ((&))
+import qualified LaunchDarkly.Server as LD
+import System.Timeout (timeout)
+import Text.Printf (printf, hPrintf)
+import System.Environment (lookupEnv)
+
+showEvaluationResult :: String -> Bool -> IO ()
+showEvaluationResult key value = do
+ printf "*** The %%s feature flag evaluates to %%s\n" key (show value)
+
+showBanner :: IO ()
+showBanner = putStr "\n\
+\ ██ \n\
+\ ██ \n\
+\ ████████ \n\
+\ ███████ \n\
+\██ LAUNCHDARKLY █\n\
+\ ███████ \n\
+\ ████████ \n\
+\ ██ \n\
+\ ██ \n\
+\\n\
+\"
+
+showMessage :: String -> Bool -> Maybe Bool -> Bool -> IO Bool
+showMessage key True _ True = do
+ showBanner
+ showEvaluationResult key True
+ pure False
+showMessage key value Nothing showBanner = do
+ showEvaluationResult key value
+ pure showBanner
+showMessage key value (Just lastValue) showBanner
+ | value /= lastValue = do
+ showEvaluationResult key value
+ pure showBanner
+ | otherwise = pure showBanner
+
+waitForClient :: LD.Client -> IO Bool
+waitForClient client = do
+ status <- LD.getStatus client
+ case status of
+ LD.Uninitialized -> threadDelay (1 * 1_000) >> waitForClient client
+ LD.Initialized -> return True
+ _anyOtherStatus -> return False
+
+evaluateLoop :: LD.Client -> String -> LD.Context -> Maybe Bool -> Bool -> IO ()
+evaluateLoop client featureFlagKey context lastValue showBanner = do
+ value <- LD.boolVariation client (pack featureFlagKey) context False
+ showBanner' <- showMessage featureFlagKey value lastValue showBanner
+
+ threadDelay (1 * 1_000_000) >> evaluateLoop client featureFlagKey context (Just value) showBanner'
+
+evaluate :: Maybe String -> Maybe String -> IO ()
+evaluate (Just sdkKey) Nothing = do evaluate (Just sdkKey) (Just "sample-feature")
+evaluate (Just sdkKey) (Just featureFlagKey) = do
+ -- Set up the evaluation context. This context should appear on your
+ -- LaunchDarkly contexts dashboard soon after you run the demo.
+ let context = LD.makeContext "example-user-key" "user" & LD.withName "Sandy"
+ client <- LD.makeClient $ LD.makeConfig (pack sdkKey)
+ initialized <- timeout (5_000 * 1_000) (waitForClient client)
--- Import the LaunchDarkly SDK.
-import LaunchDarkly.Server
+ case initialized of
+ Just True -> do
+ print "*** SDK successfully initialized!"
+ evaluateLoop client featureFlagKey context Nothing True
+ _notInitialized -> putStrLn "*** SDK failed to initialize. Please check your internet connection and SDK credential for any typo."
+evaluate _ _ = putStrLn "*** You must define LAUNCHDARKLY_SDK_KEY and LAUNCHDARKLY_FLAG_KEY before running this script"
--- Define main method
main :: IO ()
main = do
- -- Create a new LDClient instance with your environment-specific SDK Key.
- client <- makeClient $ makeConfig "1234567890abcdef"
-
- -- Set up the context properties. This context should appear on your LaunchDarkly contexts dashboard
- -- soon after you run the demo.
- let context = makeContext "example-user-key" "user"
-
- forever $ do
- -- Call LaunchDarkly with the feature flag key you want to evaluate.
- launched <- boolVariation client "my-flag-key" context False
- -- Ensure events are sent to LD immediately for fast completion of the Getting Started guide.
- -- This line is not necessary here for production use.
- flushEvents client
- putStrLn $ "Feature Flag my-flag-key is" ++ show launched
- -- one second
- threadDelay $ 1 * 1000000
+ -- Set sdkKey to your LaunchDarkly SDK key.
+ sdkKey <- lookupEnv "LAUNCHDARKLY_SDK_KEY"
+ -- Set featureFlagKey to the feature flag key you want to evaluate.
+ featureFlagKey <- lookupEnv "my-flag-key"
+ evaluate sdkKey featureFlagKey
```
Now that your application is ready, run the application to see what value we get.
diff --git a/internal/sdks/sdk_instructions/ios-swift.md b/internal/sdks/sdk_instructions/ios-swift.md
index 7a222490..cbe16e3b 100644
--- a/internal/sdks/sdk_instructions/ios-swift.md
+++ b/internal/sdks/sdk_instructions/ios-swift.md
@@ -5,7 +5,7 @@
2. Next, install the LaunchDarkly SDK using [CocoaPods](https://cocoapods.org/) by creating a `Podfile` and adding a dependency (you can also install with [Swift Package Manager](https://docs.launchdarkly.com/sdk/client-side/ios?site=launchDarkly#using-the-swift-package-manager), [Carthage](https://docs.launchdarkly.com/sdk/client-side/ios?site=launchDarkly#using-carthage), or [without a package manager](https://docs.launchdarkly.com/sdk/client-side/ios?site=launchDarkly#installing-the-sdk-manually)):
```
target 'hello-swift' do
-pod 'LaunchDarkly', '9.6.2'
+ pod 'LaunchDarkly', '9.6.2'
end
```
@@ -24,76 +24,67 @@ import LaunchDarkly
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
- var window: UIWindow?
+ var window: UIWindow?
- // Declare a variable for your mobile-specific SDK key.
- private let mobileKey = "myMobileKey"
+ // Set sdkKey to your LaunchDarkly mobile key.
+ private let sdkKey = "myMobileKey"
- func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
- setUpLDClient()
+ func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
+ setUpLDClient()
- return true
- }
-
- // Create a function to initialize the LDClient with your mobile-specific
- // SDK key, context, and optional configurations.
- private func setUpLDClient() {
- var contextBuilder = LDContextBuilder(key: "test@email.com")
- contextBuilder.trySetValue("firstName", .string("Bob"))
- contextBuilder.trySetValue("lastName", .string("Loblaw"))
- contextBuilder.trySetValue("groups", .array([.string("beta_testers")]))
+ return true
+ }
- guard case .success(let context) = contextBuilder.build()
- else { return }
+ private func setUpLDClient() {
+ // Set up the evaluation context. This context should appear on your
+ // LaunchDarkly contexts dashboard soon after you run the demo.
+ var contextBuilder = LDContextBuilder(key: "example-user-key")
+ contextBuilder.kind("user")
+ contextBuilder.name("Sandy")
- var config = LDConfig(mobileKey: mobileKey, autoEnvAttributes: .enabled)
- config.eventFlushInterval = 30.0
+ guard case .success(let context) = contextBuilder.build()
+ else { return }
- LDClient.start(config: config, context: context)
- }
+ let config = LDConfig(mobileKey: sdkKey, autoEnvAttributes: .enabled)
+ LDClient.start(config: config, context: context, startWaitSeconds: 30)
+ }
}
```
5. Open ViewController.swift and add the following code:
```swift
import UIKit
-// Import the LaunchDarkly SDK.
import LaunchDarkly
class ViewController: UIViewController {
- // Create a variable for your flag key.
- fileprivate let featureFlagKey = "my-flag-key"
- override func viewDidLoad() {
- super.viewDidLoad()
+ @IBOutlet weak var featureFlagLabel: UILabel!
- // Observe the LDClient for any feature flag updates.
- LDClient.get()?.observe(key: featureFlagKey, owner: self) { [weak self] changedFlag in
- self?.featureFlagDidUpdate(changedFlag.key)
- }
+ // Set featureFlagKey to the feature flag key you want to evaluate.
+ fileprivate let featureFlagKey = "my-flag-key"
+
+ override func viewDidLoad() {
+ super.viewDidLoad()
- checkFeatureValue()
- }
-
- // Create a function to call LaunchDarkly with the feature flag key you want to evaluate and print its value.
- fileprivate func checkFeatureValue() {
- if let featureFlagValue = LDClient.get() {
- let boolVal = featureFlagValue.boolVariation(forKey: featureFlagKey, defaultValue: false)
- // Ensure events are sent to LD immediately for fast completion of the Getting Started guide.
- // This line is not necessary here for production use.
- LDClient.get()?.flush()
- print("Feature flag (featureFlagKey) is (boolVal)")
- } else {
- print("failed to get flag, (featureFlagKey)")
+ if let ld = LDClient.get() {
+ ld.observe(key: featureFlagKey, owner: self) { [weak self] changedFlag in
+ guard let me = self else { return }
+ guard case .bool(let booleanValue) = changedFlag.newValue else { return }
+
+ me.updateUi(flagKey: changedFlag.key, result: booleanValue)
+ }
+ let result = ld.boolVariation(forKey: featureFlagKey, defaultValue: false)
+ updateUi(flagKey: featureFlagKey, result: result)
+ }
}
- }
- // Create a function to respond to flag updates.
- func featureFlagDidUpdate(_ key: LDFlagKey) {
- if key == featureFlagKey {
- checkFeatureValue()
+ func updateUi(flagKey: String, result: Bool) {
+ self.featureFlagLabel.text = "The (flagKey) feature flag evaluates to (result)"
+
+ let toggleOn = UIColor(red: 0, green: 0.52, blue: 0.29, alpha: 1)
+ let toggleOff = UIColor(red: 0.22, green: 0.22, blue: 0.25, alpha: 1)
+ self.view.backgroundColor = result ? toggleOn : toggleOff
}
- }
}
```
diff --git a/internal/sdks/sdk_instructions/java.md b/internal/sdks/sdk_instructions/java.md
index 769d4724..d4b045ba 100644
--- a/internal/sdks/sdk_instructions/java.md
+++ b/internal/sdks/sdk_instructions/java.md
@@ -4,7 +4,6 @@
mvn archetype:generate -DgroupId=com.launchdarkly.tutorial -DartifactId=hello-java
```
-
2. Change into the project directory:
```shell
cd hello-java
@@ -15,7 +14,7 @@ cd hello-java