0

How to get the datafile version/revision number from Optimizely's json file in iOS

akku
  • 3
  • 5

2 Answers2

1

Datafile version and datafile revision are two separate concepts.

The version is the internal schema version of the datafile. This is incremented whenever the datafile has new fields added to its schema like when Optimizely added feature flags.

The revision refers to which revision of your Optimizely project the datafile is at. Whenever you make a change to your Optimizely project, a new datafile is generated and the revision number is incremented.

You can get either by calling

OPTLYClient *client = [OPTLYManager initialize];
OPTLYProjectConfig *config = client.config;
NSString *version = config.version;
NSString *revision = config.revision; 
Josh Wang
  • 455
  • 3
  • 16
0

This question seems to be missing a lot of information that would be helpful. I'm not familar with Optimizely, but I dove into their documentation and found and example json formatted Datafile

The example data file shown here shows that the version number would be found under the key version and the revision number under the revision key.

If you have the file locally you would access the version and revision info like this:

NSString *path = [[NSBundle mainBundle] pathForResource:@"datafile" ofType:@"json"];
NSError *error;
NSData *data = [NSData dataWithContentsOfFile:path];
NSDictionary *dataDict =  [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
if(error) { return; } // or handle the error however you want
NSString *version = dataDict[@"version"];
NSString *revision = dataDict[@"revision"];  

If you need to grab the datafile from their server, you'll need to make a request to the appropriate end point, then serialize the JSON response. Here's the documentation I found for getting the datafile: https://docs.developers.optimizely.com/full-stack/docs/get-the-datafile#section-access-the-datafile-via-the-app

tww0003
  • 633
  • 9
  • 15