launchdarkly / ios-client-sdk

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

Starting Client doesn't bring client online #185

Closed ugiacoman closed 5 years ago

ugiacoman commented 5 years ago

Describe the bug After starting the client, I expect the client to be online. If I check the status of the client inside of its completion block, it says we are online. However, if I immediately check my variation, I get the fallback value.

To reproduce This behavior is reproducible when there is no cache, ie the first run.

func testLD() {
    let config = LDConfig(mobileKey: "test")
    let user = LDUser(key: "test")
    LDClient.shared.start(config: config, user: user) {
        if LDClient.shared.isOnline {
            let variation = LDClient.shared.variation(forKey: "key", fallback: "fallback")
            print("variation: \(variation)") // prints "variation: fallback"
        }
    }

    // If I run this method after calling start and then try
    // accessing my variation inside of the callback, I get the actual value
    LDClient.shared.setOnline(true) {
        let variation = LDClient.shared.variation(forKey: "key", fallback: "fallback")
        print("variation: \(variation)") // prints "variation: on"
    }
}

Expected behavior Accessing variation after starting the client should work if we are online.

Logs N/A

SDK version 4.1.0

Language version, developer tools N/A

OS/platform iOS

Additional context N/A

torchhound commented 5 years ago

Hi @ugiacoman, thanks for the report! isOnline is a slightly deceptive name because it indicates connection status but not whether the SDK has received flag values. Your completion closure on setOnline is called when flag values are received. I recommend using a completion closure on the start method which is called after setOnline is called and completed internally. This should allow your application to continue once flag values are received on startup including cold starts. If you have other questions or concerns please respond in this issue or reach out to support.

lazyvar commented 4 years ago

Hi @torchhound, I am experience issues similar to the original poster. After reading your comment are you recommending something like the following?

LDClient.shared.start(config: config, user: user) {
   let variation = LDClient.shared.variation(forKey: "key", fallback: "fallback")
   print("variation: \(variation)") // prints "variation: fallback"
}

The above solution consistently prints "fallback" for me. Is there a notification or closure in the SDK we should be using to know when it is safe to ask for variations from LDClient aka as you put it "has received flag values"? Thank you!

brooswit commented 4 years ago

Hi @lazyvar,

Thanks for reaching out! I see you also submitted a support request. This is more of a support issue, rather than an engineering issue. I'll help you via your support request shortly.