iosobjective-coptimizely

How to get the datafile version number of optimizely in iOS SDK?


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


Solution

  • 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