Skip to content

Commit 3b31260

Browse files
authored
feat(decide): add a new set of decide apis (#373)
Add a new set of decide apis - add OptimizelyUserContext (setAttribute/decide/decideAll) - add OptimizelyDecision - add "createUserContext" to OptimizelyClient
1 parent faafa82 commit 3b31260

File tree

66 files changed

+4487
-588
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+4487
-588
lines changed

DemoObjCApp/AppDelegate.m

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************
2-
* Copyright 2019-2020, Optimizely, Inc. and contributors *
2+
* Copyright 2019-2021, Optimizely, Inc. and contributors *
33
* *
44
* Licensed under the Apache License, Version 2.0 (the "License"); *
55
* you may not use this file except in compliance with the License. *
@@ -24,21 +24,23 @@
2424

2525
static NSString * const kOptimizelySdkKey = @"FCnSegiEkRry9rhVMroit4";
2626
static NSString * const kOptimizelyDatafileName = @"demoTestDatafile";
27-
static NSString * const kOptimizelyExperimentKey = @"background_experiment";
27+
static NSString * const kOptimizelyFeatureKey = @"decide_demo";
28+
static NSString * const kOptimizelyExperimentKey = @"background_experiment_decide";
2829
static NSString * const kOptimizelyEventKey = @"sample_conversion";
2930

3031
@interface AppDelegate ()
3132
@property(nonnull, strong, nonatomic) NSString *userId;
3233
@property(nonnull, strong, nonatomic) NSDictionary *attributes;
3334
@property(nullable, strong, nonatomic) OptimizelyClient *optimizely;
35+
@property(nullable, strong, nonatomic) OptimizelyUserContext *user;
3436
@end
3537

3638
@implementation AppDelegate
3739

3840
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
3941

4042
self.userId = [NSString stringWithFormat:@"%d", arc4random_uniform(300000)];
41-
self.attributes = @{ @"browser_type": @"safari" };
43+
self.attributes = @{ @"location": @"CA", @"semanticVersioning": @"1.2"};
4244

4345
// initialize SDK in one of these two ways:
4446
// (1) asynchronous SDK initialization (RECOMMENDED)
@@ -134,6 +136,7 @@ -(void)initializeOptimizelySDKWithCustomization {
134136

135137
// For sample codes for APIs, see "Samples/SamplesForAPI.swift"
136138
//[SamplesForAPI checkOptimizelyConfig:self.optimizely];
139+
//[SamplesForAPI checkOptimizelyUserContext:self.optimizely];
137140
}];
138141
}
139142

@@ -166,16 +169,16 @@ -(void)startWithRootViewController {
166169
dispatch_async(dispatch_get_main_queue(), ^{
167170
// For sample codes for other APIs, see "Samples/SamplesForAPI.m"
168171

169-
NSError *error;
170-
NSString *variationKey = [self.optimizely activateWithExperimentKey:kOptimizelyExperimentKey
171-
userId:self.userId
172-
attributes:self.attributes
173-
error:&error];
172+
self.user = [self.optimizely createUserContextWithUserId:self.userId
173+
attributes:self.attributes];
174+
175+
OptimizelyDecision *decision = [self.user decideWithKey:kOptimizelyFeatureKey
176+
options:@[@(OptimizelyDecideOptionIncludeReasons)]];
174177

175-
if (variationKey != nil) {
176-
[self openVariationViewWithVariationKey:variationKey];
178+
if (decision.variationKey != nil) {
179+
[self openVariationViewWithVariationKey:decision.variationKey];
177180
} else {
178-
NSLog(@"Optimizely SDK activation failed: %@", error.localizedDescription);
181+
NSLog(@"Optimizely SDK activation failed: %@", decision.reasons);
179182
[self openFailureView];
180183
}
181184
});

DemoObjCApp/DemoObjcApp.xcodeproj/project.pbxproj

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,20 @@
134134
remoteGlobalIDString = 6E614DCC21E3F389005982A1;
135135
remoteInfo = "OptimizelySwiftSDK-tvOS";
136136
};
137+
6EF41A992523D23E00EAADF1 /* PBXContainerItemProxy */ = {
138+
isa = PBXContainerItemProxy;
139+
containerPortal = 6E4D2FE722C5457F00062EB3 /* OptimizelySwiftSDK.xcodeproj */;
140+
proxyType = 2;
141+
remoteGlobalIDString = BD6485812491474500F30986;
142+
remoteInfo = "OptimizelySwiftSDK-macOS";
143+
};
144+
6EF41A9B2523D23E00EAADF1 /* PBXContainerItemProxy */ = {
145+
isa = PBXContainerItemProxy;
146+
containerPortal = 6E4D2FE722C5457F00062EB3 /* OptimizelySwiftSDK.xcodeproj */;
147+
proxyType = 2;
148+
remoteGlobalIDString = 6E14CD632423F80B00010234;
149+
remoteInfo = "OptimizelyTests-Batch-iOS";
150+
};
137151
/* End PBXContainerItemProxy section */
138152

139153
/* Begin PBXCopyFilesBuildPhase section */
@@ -218,8 +232,10 @@
218232
children = (
219233
6E4D2FF722C5457F00062EB3 /* Optimizely.framework */,
220234
6E4D2FF922C5457F00062EB3 /* Optimizely.framework */,
235+
6EF41A9A2523D23E00EAADF1 /* Optimizely.framework */,
221236
6E4D2FFB22C5457F00062EB3 /* OptimizelyTests-iOS.xctest */,
222237
6E4D2FFD22C5457F00062EB3 /* OptimizelyTests-Common-iOS.xctest */,
238+
6EF41A9C2523D23E00EAADF1 /* OptimizelyTests-Batch-iOS.xctest */,
223239
6E4D2FFF22C5457F00062EB3 /* OptimizelyTests-APIs-iOS.xctest */,
224240
6E4D300122C5457F00062EB3 /* OptimizelyTests-DataModel-iOS.xctest */,
225241
6E4D300322C5457F00062EB3 /* OptimizelyTests-Others-iOS.xctest */,
@@ -403,7 +419,7 @@
403419
6EF7496721E40467008B22A0 /* Project object */ = {
404420
isa = PBXProject;
405421
attributes = {
406-
LastUpgradeCheck = 1010;
422+
LastUpgradeCheck = 1200;
407423
ORGANIZATIONNAME = Optimizely;
408424
TargetAttributes = {
409425
6EF7498D21E404BB008B22A0 = {
@@ -529,6 +545,20 @@
529545
remoteRef = 6E4D300C22C5457F00062EB3 /* PBXContainerItemProxy */;
530546
sourceTree = BUILT_PRODUCTS_DIR;
531547
};
548+
6EF41A9A2523D23E00EAADF1 /* Optimizely.framework */ = {
549+
isa = PBXReferenceProxy;
550+
fileType = wrapper.framework;
551+
path = Optimizely.framework;
552+
remoteRef = 6EF41A992523D23E00EAADF1 /* PBXContainerItemProxy */;
553+
sourceTree = BUILT_PRODUCTS_DIR;
554+
};
555+
6EF41A9C2523D23E00EAADF1 /* OptimizelyTests-Batch-iOS.xctest */ = {
556+
isa = PBXReferenceProxy;
557+
fileType = wrapper.cfbundle;
558+
path = "OptimizelyTests-Batch-iOS.xctest";
559+
remoteRef = 6EF41A9B2523D23E00EAADF1 /* PBXContainerItemProxy */;
560+
sourceTree = BUILT_PRODUCTS_DIR;
561+
};
532562
/* End PBXReferenceProxy section */
533563

534564
/* Begin PBXResourcesBuildPhase section */

DemoObjCApp/DemoObjcApp.xcodeproj/xcshareddata/xcschemes/DemoObjciOS.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1130"
3+
LastUpgradeVersion = "1200"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

DemoObjCApp/DemoObjcApp.xcodeproj/xcshareddata/xcschemes/DemoObjctvOS.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1130"
3+
LastUpgradeVersion = "1200"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

0 commit comments

Comments
 (0)