launchdarkly / ios-client-sdk

LaunchDarkly Client-side SDK for iOS (Swift and Obj-C)
https://docs.launchdarkly.com/sdk/client-side/ios
Other
68 stars 82 forks source link

Calling LDClient.start resets application AccentColor #305

Closed michaelaflores closed 9 months ago

michaelaflores commented 10 months ago

Is this a support request? No

Describe the bug I have an application which defines AccentColor in Assets as an orange color. In my SwiftUI app, this causes the default color of buttons to be an orange color rather than blue. In my application init code, if I allow the below line LDClient.start to be called, then the buttons are reset to their blue color rather than appearing orange. When the line is commented out, buttons display as the color defined in Assets AccentColor.

// My app init code
//
//  TUNE_OSApp.swift
//  TUNE OS
//
//  Created by Michael Flores on 6/29/23.
//

import SwiftUI
import Mixpanel
import LaunchDarkly

@main
struct TUNE_OSApp: App {
    let persistenceController = PersistenceController.shared
    @StateObject var bluetoothManager = BluetoothManager()
    @StateObject private var viewModel = MainViewModel()
    private let mobileKey = "key"
    @Environment(\.scenePhase) var scenePhase

    init() {
        Mixpanel.initialize(token: "token", trackAutomaticEvents: true)
        setUpLDClient()
        print("Application completed init")
    }

    var body: some Scene {
        WindowGroup {
            MainView()
        }
    }

    private func setUpLDClient() {
      var contextBuilder = LDContextBuilder(key: "unknown-user")
      contextBuilder.trySetValue("groups", .array([.string("testflight_beta_testers")]))

      guard case .success(let context) = contextBuilder.build()
      else { return }

      var config = LDConfig(mobileKey: mobileKey, autoEnvAttributes: .enabled)
      config.eventFlushInterval = 30.0

      LDClient.start(config: config, context: context)
    }
}

To reproduce In a SwiftUI app running on iPadOS 16.6, using the above code, and with AccentColor defined in Assets as some non-blue color, run a build on your physical device. Run once with LDClient.start(config: config, context: context) commented out, and once with it uncommented, and observe the change of button color.

Note this reproduces on iPadOS and iOS when running on those physical devices, not in simulator.

Expected behavior Calling LDClient.start should have no effect on application appearance.

Logs

2023-09-04 15:27:06.139368-0400 TUNE OS[482:7470] <SKPaymentQueue: 0x283ce8ac0>: No observers found that respond to "paymentQueue:shouldAddStorePayment:forProduct:", will not check for purchase intents
Application completed init
2023-09-04 15:27:06.204989-0400 TUNE OS[482:7669] [LDEventSource] State: raw -> connecting
2023-09-04 15:27:06.205187-0400 TUNE OS[482:7669] [LDEventSource] Starting EventSource client
DeviceViewModel: init()
MainViewModel: starting
MainViewModel: no stored peripheral under key selectedPeripheral, so not automatically connecting
LaunchDarkly: the value of welcome-screen is false
MainViewModel: calling manager scan
BluetoothManager: starting to scan for peripherals
BluetoothManager: state did update to bluetooth .poweredOn
2023-09-04 15:27:06.570987-0400 TUNE OS[482:7668] [LDEventSource] Initial reply received
2023-09-04 15:27:06.571012-0400 TUNE OS[482:7668] [LDEventSource] State: connecting -> open
LaunchDarkly: the value of welcome-screen is false

SDK version 9.0.2

Language version, developer tools Swift 5.8

OS/platform iOS 16.6, iPadOS 16.6

Additional context After calling LDClient.start IMG_FC719E09DDC7-1

Without calling LDClient.start IMG_318FCF70B405-1

tanderson-ld commented 10 months ago

Hi @michaelaflores , thank you for taking the time to submit an issue. The SDK has no asset logic in it. I just double checked that there is no asset logic and no usage of "Accent Color".

My initial theory is there is some piece of code that is interacting with a flag in an unexpected manner or perhaps a default value is being retrieved while the SDK is starting up. Do you use any feature flags for influencing the behavior of the UI layer?

Did you notice this behavior upon updating to 9.0.2 or is this the first version of the SDK being used in this app? If 9.0.2 is the first version you have used, would mind downgrading to 8.2.0 and seeing if you see the issue on that version as well? You'll have to remove the autoEnvAttributes parameter when doing this downgrade test since that was added in 9.x.

Thanks!

tanderson-ld commented 9 months ago

@michaelaflores , this issue has been inactive for a time and we are closing it. Please leave a comment if you'd like to continue discussing this issue.