optimizely/objective-c-sdk

Initialise OPTLYDatafileManagerDefault with SDK key

afonsograca opened this issue · 2 comments

Hi!
In your 2.1 release you state the following:

Introduces SDK Keys, which allow you to use Environments with the Objective-C SDK. Use an SDK Key to initialize your OptimizelyManager, and the SDK will retrieve the datafile for the environment associated with the SDK Key. This replaces initialization with Project ID.

However, to create my OPTLYDatafileManagerDefault, I need to create a OPTLYDatafileManagerBuilder which in turn requires a OPTLYDatafileConfig that can only be initialised with a projectId and a sdkKey.

So how can I initialise my OPTLYDatafileManagerDefault with just having my SDK key?

Also, the examples on how to configure the datafile manager found here do not work, OPTLYDatafileManagerBuilder does not have a sdkKey member and the initialiser used is the deprecated one.

Cheers

@afonsograca thanks for the feedback. We updated the docs. But, I'm cutting and pasting the code here for you as well:
Objective-C

// Create the datafile manager and set the datafile fetch interval
OPTLYDatafileManager *datafileManager =
    [OPTLYDatafileManagerDefault init:^(OPTLYDatafileManagerBuilder * _Nullable builder) {
    builder.datafileConfig = [[OPTLYDatafileConfig alloc] initWithProjectId:nil withSDKKey:@"SDK_KEY_HERE"];
    // Poll every 2 minutes
    builder.datafileFetchInterval = 120.0;
}];

// Create the manager and set the datafile manager
OPTLYManager *manager = [OPTLYManager init:^(OPTLYManagerBuilder * _Nullable builder) {
    builder.sdkKey = @"SDK_KEY_HERE";
    builder.datafileManager = datafileManager;
}];

Swift

// ---- Create the Datafile Manager ----
let datafileManager = OPTLYDatafileManagerDefault(builder: OPTLYDatafileManagerBuilder(block: { (builder) in
builder!.datafileFetchInterval = TimeInterval(self.datafileManagerDownloadInterval)
builder!.datafileConfig = OPTLYDatafileConfig(projectId: nil, withSDKKey:"FCnSegiEkRry9rhVMroit4")!;

}))

// ---- Create the Manager Builder ----
let builder = OPTLYManagerBuilder(block: { (builder) in
builder!.projectId = nil;
builder!.sdkKey = "FCnSegiEkRry9rhVMroit4"
builder!.datafileManager = datafileManager!
})

// ---- Create the Manager ----
let optimizelyManager = OPTLYManager(builder: builder)

documentation has been updated. we are closing this issue. thanks!