ios-client-sdk icon indicating copy to clipboard operation
ios-client-sdk copied to clipboard

Feature Flag value is not being fetched on first time

Open mohsinbmwm3 opened this issue 7 months ago • 4 comments

Describe the bug iOS LD SDK is not able to fetch boolean value on launching app, we have to launch app second time to fetch current value.

To reproduce

  • Launch the ios app and let it fetch FF value.
  • Now kill the app and after killing change the FF value in LD portal.
  • Now launch iOS app and you will see that changed value wont be reflected in the iOS app.
  • Now kill the app again and launch it again, you will see latest value will be reflected here.

One more observation(here we are not killing ios app while changing values in LD portal):

  • Launch the ios app and let it fetch FF value.
  • Now without killing the app change the FF value in LD portal.
  • Now kill the app and relaunch the app and you will see correct value is being reflected in the app.

Expected behavior When we update value in LD portal, ios SDK should automatically fetch or point to that updated value.

Library version pod 'LaunchDarkly', '~> 6.0' XCode and Swift version Xcode Version 15.2, Swift 5.0

Platform the issue occurs on iPhone

Additional context I have configured a bool Feature flag, also made available to mobile. Also same ff is being fetched properly in android, not just in ios somehow it is fetching value in second launch of the app

Code

 - (void) updateUser:(User *)user AndHubInfo:(Hub *)hub {
    LDUser *ldUser = [self buildLDUser:user withHubInfo:hub];
    [self updateLDLibrary:ldUser];
}

 - (BOOL) getFlagValue:(NSString *)featureName defaultValue:(BOOL)value {
    BOOL ffValue = [[LDClient get] boolVariationForKey:featureName defaultValue:NO];    
    return ffValue;
}
 - (LDUser *) buildLDUser:(User *)user withHubInfo:(Hub *)hub {
    LDUser *ldUser = [[LDUser alloc] initWithKey:someRandomId];
    ldUser.email = user.email;
    ldUser.privateAttributes = @[@"email"];
    
    NSMutableDictionary *dict = [self getCustomKeys:hub];
    if (dict != nil) {
        ldUser.custom = dict;
        if ([ldUser.custom objectForKey:kADLDHubID] != nil)
            ldUser.privateAttributes = @[@"email", HubId];
    }
    return ldUser;
}
 - (void) updateLibrary:(LDUser *)ldUser {
    LDConfig *config = [[LDConfig alloc] initWithMobileKey:LaunchDarklyKey];
    [config setStartOnline:YES];
#ifdef DEBUG
    [config setDebugMode:YES];
    [config setDiagnosticOptOut:YES];
#endif
    [config setEvaluationReasons:YES];
    
    [LDClient startWithConfiguration:config user:ldUser completion:^{
    }];
}

mohsinbmwm3 avatar Jul 18 '24 15:07 mohsinbmwm3