Skip to content

chore(test-app): start a second environment when a second key is set - #550

Open
abelonogov-ld wants to merge 1 commit into
andrey/apple-test-appfrom
andrey/apple-test-app-two-environments
Open

abelonogov-ld wants to merge 1 commit into
andrey/apple-test-appfrom
andrey/apple-test-app-two-environments

Conversation

@abelonogov-ld

@abelonogov-ld abelonogov-ld commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #545.

What

When Config/Secrets.xcconfig sets LAUNCHDARKLY_SECONDARY_MOBILE_KEY (or the app is launched with -LDSecondaryMobileKey mob-...), the client is started with that key as a secondary environment through LDConfig.setSecondaryMobileKeys. An Environment picker at the top of Client chooses which environment's client the buttons use. Without the key nothing changes.

The selected environment is used by:

  • Eval, All flags, and the flag-change observer;
  • Track;
  • Kill 5s, Kill now, Fatal now, Over-refresh and Fill 3 batches;
  • Post 20 MB (which key it posts with);
  • the connection status;
  • Event storage, which shows that environment's own directory.

These reach both environments whichever is selected, because the SDK applies close, flush, flushAndWait, setOnline and identify to every environment it started: Restart and the persistence picker, Flush, Flush+Wait, Offline, and Identify. A footer under Client says so.

The choice is saved in UserDefaults, so the launch that answers a kill scenario shows the same environment. InstanceLauncher forwards -LDSecondaryMobileKey to the instances it starts.

Testing

  • All five targets build: iOS (simulator and Mac Catalyst), macOS, tvOS and watchOS.
  • Ran on an iPhone 17 simulator with both keys set:
    • the picker appears and switches the connection status;
    • with immediate persistence, each environment writes its own event directory (<bundle hash>.<key hash>), each holding its startup log.

Note

The SDK keeps ConnectionInformation under one UserDefaults key for every environment (ConnectionInformationStore). Each environment's status therefore starts out showing whichever environment saved last, until its own connection updates it. This PR doesn't change that SDK behavior.


Note

Overview
The TestApp can now run two LaunchDarkly environments when LAUNCHDARKLY_SECONDARY_MOBILE_KEY is set (or -LDSecondaryMobileKey at launch). LDConfig.setSecondaryMobileKeys starts the secondary client alongside the primary; config, plist, and README document the new key.

Environment picker appears on Client when a distinct secondary key is present. The choice is persisted in UserDefaults so kill/crash relaunch scenarios keep the same environment. Per-environment behavior covers flag eval/observers, track, stress and event-loss actions, connection status, event storage (per-directory via .id), and the oversized POST probe’s API key.

Global SDK operations still hit both environments: restart, flush, offline, and identify—called out in a section footer. InstanceLauncher forwards the secondary key to spawned instances.

Reviewed by Cursor Bugbot for commit a796dca. Bugbot is set up for automated code reviews on this repo. Configure here.

LAUNCHDARKLY_SECONDARY_MOBILE_KEY in Secrets.xcconfig, or -LDSecondaryMobileKey at launch, adds a
secondary mobile key to the client's LDConfig. An Environment picker then chooses which environment's
client the buttons, the connection status, Post 20 MB and the Event storage section use. Restart,
Flush, Flush+Wait, Offline and Identify still reach both, as the SDK applies them to every environment.

Co-authored-by: Cursor <cursoragent@cursor.com>
@abelonogov-ld
abelonogov-ld requested a review from a team as a code owner November 11, 2026 01:46

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant