diff --git a/DemoObjCApp/AppDelegate.m b/DemoObjCApp/AppDelegate.m index bce0eb7de..c509de00b 100644 --- a/DemoObjCApp/AppDelegate.m +++ b/DemoObjCApp/AppDelegate.m @@ -1,5 +1,5 @@ /**************************************************************************** -* Copyright 2019-2020, Optimizely, Inc. and contributors * +* Copyright 2019-2021, Optimizely, Inc. and contributors * * * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * @@ -24,13 +24,15 @@ static NSString * const kOptimizelySdkKey = @"FCnSegiEkRry9rhVMroit4"; static NSString * const kOptimizelyDatafileName = @"demoTestDatafile"; -static NSString * const kOptimizelyExperimentKey = @"background_experiment"; +static NSString * const kOptimizelyFeatureKey = @"decide_demo"; +static NSString * const kOptimizelyExperimentKey = @"background_experiment_decide"; static NSString * const kOptimizelyEventKey = @"sample_conversion"; @interface AppDelegate () @property(nonnull, strong, nonatomic) NSString *userId; @property(nonnull, strong, nonatomic) NSDictionary *attributes; @property(nullable, strong, nonatomic) OptimizelyClient *optimizely; +@property(nullable, strong, nonatomic) OptimizelyUserContext *user; @end @implementation AppDelegate @@ -38,7 +40,7 @@ @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.userId = [NSString stringWithFormat:@"%d", arc4random_uniform(300000)]; - self.attributes = @{ @"browser_type": @"safari" }; + self.attributes = @{ @"location": @"CA", @"semanticVersioning": @"1.2"}; // initialize SDK in one of these two ways: // (1) asynchronous SDK initialization (RECOMMENDED) @@ -134,6 +136,7 @@ -(void)initializeOptimizelySDKWithCustomization { // For sample codes for APIs, see "Samples/SamplesForAPI.swift" //[SamplesForAPI checkOptimizelyConfig:self.optimizely]; + //[SamplesForAPI checkOptimizelyUserContext:self.optimizely]; }]; } @@ -166,16 +169,16 @@ -(void)startWithRootViewController { dispatch_async(dispatch_get_main_queue(), ^{ // For sample codes for other APIs, see "Samples/SamplesForAPI.m" - NSError *error; - NSString *variationKey = [self.optimizely activateWithExperimentKey:kOptimizelyExperimentKey - userId:self.userId - attributes:self.attributes - error:&error]; + self.user = [self.optimizely createUserContextWithUserId:self.userId + attributes:self.attributes]; + + OptimizelyDecision *decision = [self.user decideWithKey:kOptimizelyFeatureKey + options:@[@(OptimizelyDecideOptionIncludeReasons)]]; - if (variationKey != nil) { - [self openVariationViewWithVariationKey:variationKey]; + if (decision.variationKey != nil) { + [self openVariationViewWithVariationKey:decision.variationKey]; } else { - NSLog(@"Optimizely SDK activation failed: %@", error.localizedDescription); + NSLog(@"Optimizely SDK activation failed: %@", decision.reasons); [self openFailureView]; } }); diff --git a/DemoObjCApp/DemoObjcApp.xcodeproj/project.pbxproj b/DemoObjCApp/DemoObjcApp.xcodeproj/project.pbxproj index 2cbbb646d..ac71754fc 100644 --- a/DemoObjCApp/DemoObjcApp.xcodeproj/project.pbxproj +++ b/DemoObjCApp/DemoObjcApp.xcodeproj/project.pbxproj @@ -134,6 +134,20 @@ remoteGlobalIDString = 6E614DCC21E3F389005982A1; remoteInfo = "OptimizelySwiftSDK-tvOS"; }; + 6EF41A992523D23E00EAADF1 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 6E4D2FE722C5457F00062EB3 /* OptimizelySwiftSDK.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = BD6485812491474500F30986; + remoteInfo = "OptimizelySwiftSDK-macOS"; + }; + 6EF41A9B2523D23E00EAADF1 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 6E4D2FE722C5457F00062EB3 /* OptimizelySwiftSDK.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 6E14CD632423F80B00010234; + remoteInfo = "OptimizelyTests-Batch-iOS"; + }; /* End PBXContainerItemProxy section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -218,8 +232,10 @@ children = ( 6E4D2FF722C5457F00062EB3 /* Optimizely.framework */, 6E4D2FF922C5457F00062EB3 /* Optimizely.framework */, + 6EF41A9A2523D23E00EAADF1 /* Optimizely.framework */, 6E4D2FFB22C5457F00062EB3 /* OptimizelyTests-iOS.xctest */, 6E4D2FFD22C5457F00062EB3 /* OptimizelyTests-Common-iOS.xctest */, + 6EF41A9C2523D23E00EAADF1 /* OptimizelyTests-Batch-iOS.xctest */, 6E4D2FFF22C5457F00062EB3 /* OptimizelyTests-APIs-iOS.xctest */, 6E4D300122C5457F00062EB3 /* OptimizelyTests-DataModel-iOS.xctest */, 6E4D300322C5457F00062EB3 /* OptimizelyTests-Others-iOS.xctest */, @@ -403,7 +419,7 @@ 6EF7496721E40467008B22A0 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1010; + LastUpgradeCheck = 1200; ORGANIZATIONNAME = Optimizely; TargetAttributes = { 6EF7498D21E404BB008B22A0 = { @@ -529,6 +545,20 @@ remoteRef = 6E4D300C22C5457F00062EB3 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; + 6EF41A9A2523D23E00EAADF1 /* Optimizely.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = Optimizely.framework; + remoteRef = 6EF41A992523D23E00EAADF1 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 6EF41A9C2523D23E00EAADF1 /* OptimizelyTests-Batch-iOS.xctest */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = "OptimizelyTests-Batch-iOS.xctest"; + remoteRef = 6EF41A9B2523D23E00EAADF1 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; /* End PBXReferenceProxy section */ /* Begin PBXResourcesBuildPhase section */ diff --git a/DemoObjCApp/DemoObjcApp.xcodeproj/xcshareddata/xcschemes/DemoObjciOS.xcscheme b/DemoObjCApp/DemoObjcApp.xcodeproj/xcshareddata/xcschemes/DemoObjciOS.xcscheme index 4d7d980d9..f50f01236 100644 --- a/DemoObjCApp/DemoObjcApp.xcodeproj/xcshareddata/xcschemes/DemoObjciOS.xcscheme +++ b/DemoObjCApp/DemoObjcApp.xcodeproj/xcshareddata/xcschemes/DemoObjciOS.xcscheme @@ -1,6 +1,6 @@ - - - - + + - + + @@ -29,15 +28,15 @@ - + - + @@ -54,14 +53,14 @@ - + - + - + @@ -97,24 +96,24 @@ - - - + - - - - - - - + + + + - - - + + - + + + + - - + - - @@ -215,21 +206,21 @@ - + - + - + -