Skip to content

Commit baeca1e

Browse files
committed
fix conflicts
2 parents f46efa3 + 6157806 commit baeca1e

31 files changed

+475
-344
lines changed

DemoObjCApp/AppDelegate.m

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
#import "AppDelegate.h"
1818
#import "VariationViewController.h"
19-
#import "FailureViewController.h"
2019
#import "CustomLogger.h"
20+
#import "SamplesForAPI.h"
2121

2222
@import Optimizely;
2323
#if TARGET_OS_IOS
@@ -65,7 +65,6 @@ -(void)initializeOptimizelySDKAsynchronous {
6565
NSLog(@"Optimizely SDK initialized successfully!");
6666
} else {
6767
NSLog(@"Optimizely SDK initiliazation failed: %@", error.localizedDescription);
68-
self.optimizely = nil;
6968
}
7069

7170
[self startWithRootViewController];
@@ -76,7 +75,6 @@ -(void)initializeOptimizelySDKSynchronous {
7675
NSString *localDatafilePath = [[NSBundle mainBundle] pathForResource:kOptimizelyDatafileName ofType:@"json"];
7776
if (localDatafilePath == nil) {
7877
NSAssert(false, @"Local datafile cannot be found");
79-
self.optimizely = nil;
8078
return;
8179
}
8280

@@ -86,15 +84,13 @@ -(void)initializeOptimizelySDKSynchronous {
8684

8785
if (datafileJSON == nil) {
8886
NSLog(@"Invalid JSON format");
89-
self.optimizely = nil;
9087
} else {
9188
NSError *error;
9289
BOOL status = [self.optimizely startWithDatafile:datafileJSON error:&error];
9390
if (status) {
9491
NSLog(@"Optimizely SDK initialized successfully!");
9592
} else {
9693
NSLog(@"Optimizely SDK initiliazation failed: %@", error.localizedDescription);
97-
self.optimizely = nil;
9894
}
9995
}
10096

@@ -150,7 +146,6 @@ -(void)initializeOptimizelySDKWithCustomization {
150146
NSLog(@"Optimizely SDK initialized successfully!");
151147
} else {
152148
NSLog(@"Optimizely SDK initiliazation failed: %@", error.localizedDescription);
153-
self.optimizely = nil;
154149
}
155150

156151
[self startWithRootViewController];
@@ -161,12 +156,14 @@ -(void)initializeOptimizelySDKWithCustomization {
161156

162157
-(void)startWithRootViewController {
163158
dispatch_async(dispatch_get_main_queue(), ^{
159+
// For sample codes for other APIs, see "Samples/SamplesForAPI.m"
160+
164161
NSError *error;
165162
NSString *variationKey = [self.optimizely activateWithExperimentKey:kOptimizelyExperimentKey
166163
userId:self.userId
167164
attributes:self.attributes
168165
error:&error];
169-
166+
170167
if (variationKey != nil) {
171168
[self openVariationViewWithVariationKey:variationKey];
172169
} else {

DemoObjCApp/DemoObjcApp.xcodeproj/project.pbxproj

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@
2525
6E9681B221EEA3D8009B7FEC /* ProximaNova-Regular.otf in Resources */ = {isa = PBXBuildFile; fileRef = 6E9681A921EEA3D8009B7FEC /* ProximaNova-Regular.otf */; };
2626
6E9681B321EEA3D8009B7FEC /* ProximaNova-Regular.otf in Resources */ = {isa = PBXBuildFile; fileRef = 6E9681A921EEA3D8009B7FEC /* ProximaNova-Regular.otf */; };
2727
6E9681BA21EEB361009B7FEC /* VariationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EB8456521EE5DE3005346CC /* VariationViewController.m */; };
28-
6E9681BB21EEB361009B7FEC /* FailureViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EB8456721EE5DE3005346CC /* FailureViewController.m */; };
29-
6E9681BC21EEB361009B7FEC /* SplashScreenViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EB8456921EE5DE3005346CC /* SplashScreenViewController.m */; };
3028
6E9681BD21EEB364009B7FEC /* VariationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EB8456521EE5DE3005346CC /* VariationViewController.m */; };
31-
6E9681BE21EEB364009B7FEC /* FailureViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EB8456721EE5DE3005346CC /* FailureViewController.m */; };
32-
6E9681BF21EEB364009B7FEC /* SplashScreenViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EB8456921EE5DE3005346CC /* SplashScreenViewController.m */; };
3329
6E9681D821EFA5B2009B7FEC /* CustomLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E9681D721EFA5B2009B7FEC /* CustomLogger.m */; };
3430
6E9681D921EFA5B2009B7FEC /* CustomLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = 6E9681D721EFA5B2009B7FEC /* CustomLogger.m */; };
3531
6EB8456B21EE5DE3005346CC /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EB8456421EE5DE3005346CC /* AppDelegate.m */; };
3632
6EB8456C21EE5DE3005346CC /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EB8456421EE5DE3005346CC /* AppDelegate.m */; };
33+
6EFA3206227CD55E006FA572 /* SamplesForAPI.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EFA3205227CD55E006FA572 /* SamplesForAPI.m */; };
34+
6EFA3207227CD55E006FA572 /* SamplesForAPI.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EFA3205227CD55E006FA572 /* SamplesForAPI.m */; };
3735
A0C60F82A88EDB74234D7D3F /* Pods_DemoObjctvOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 48C9592909E0CF5074F9A84D /* Pods_DemoObjctvOS.framework */; };
3836
/* End PBXBuildFile section */
3937

@@ -178,17 +176,15 @@
178176
6E9681A921EEA3D8009B7FEC /* ProximaNova-Regular.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "ProximaNova-Regular.otf"; sourceTree = "<group>"; };
179177
6E9681D421EFA5B2009B7FEC /* CustomLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomLogger.h; sourceTree = "<group>"; };
180178
6E9681D721EFA5B2009B7FEC /* CustomLogger.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomLogger.m; sourceTree = "<group>"; };
181-
6EB8456321EE5DE3005346CC /* SplashScreenViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SplashScreenViewController.h; sourceTree = "<group>"; };
182179
6EB8456421EE5DE3005346CC /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
183180
6EB8456521EE5DE3005346CC /* VariationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VariationViewController.m; sourceTree = "<group>"; };
184181
6EB8456621EE5DE3005346CC /* VariationViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VariationViewController.h; sourceTree = "<group>"; };
185-
6EB8456721EE5DE3005346CC /* FailureViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FailureViewController.m; sourceTree = "<group>"; };
186-
6EB8456821EE5DE3005346CC /* FailureViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FailureViewController.h; sourceTree = "<group>"; };
187-
6EB8456921EE5DE3005346CC /* SplashScreenViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SplashScreenViewController.m; sourceTree = "<group>"; };
188182
6EB8456A21EE5DE3005346CC /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
189183
6EF7498E21E404BB008B22A0 /* DemoObjciOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DemoObjciOS.app; sourceTree = BUILT_PRODUCTS_DIR; };
190184
6EF7499F21E404BC008B22A0 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
191185
6EF749A821E404D6008B22A0 /* DemoObjctvOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DemoObjctvOS.app; sourceTree = BUILT_PRODUCTS_DIR; };
186+
6EFA3204227CD55E006FA572 /* SamplesForAPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SamplesForAPI.h; sourceTree = "<group>"; };
187+
6EFA3205227CD55E006FA572 /* SamplesForAPI.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SamplesForAPI.m; sourceTree = "<group>"; };
192188
762D1F9E4AA702083D17C4C9 /* Pods-DemoObjciOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DemoObjciOS.release.xcconfig"; path = "../Pods/Target Support Files/Pods-DemoObjciOS/Pods-DemoObjciOS.release.xcconfig"; sourceTree = "<group>"; };
193189
D47F5FC88600AFD4E656D50A /* Pods-DemoObjciOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DemoObjciOS.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-DemoObjciOS/Pods-DemoObjciOS.debug.xcconfig"; sourceTree = "<group>"; };
194190
D58542E1B5771327083E56E2 /* Pods-DemoObjctvOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DemoObjctvOS.release.xcconfig"; path = "../Pods/Target Support Files/Pods-DemoObjctvOS/Pods-DemoObjctvOS.release.xcconfig"; sourceTree = "<group>"; };
@@ -307,11 +303,8 @@
307303
6EB8456421EE5DE3005346CC /* AppDelegate.m */,
308304
6EB8456621EE5DE3005346CC /* VariationViewController.h */,
309305
6EB8456521EE5DE3005346CC /* VariationViewController.m */,
310-
6EB8456821EE5DE3005346CC /* FailureViewController.h */,
311-
6EB8456721EE5DE3005346CC /* FailureViewController.m */,
312-
6EB8456321EE5DE3005346CC /* SplashScreenViewController.h */,
313-
6EB8456921EE5DE3005346CC /* SplashScreenViewController.m */,
314306
6E96812021EE957B009B7FEC /* Customization */,
307+
6EFA322A227CDDF0006FA572 /* Samples */,
315308
6E96817721EEA321009B7FEC /* DemoObjciOS */,
316309
6E96817321EEA321009B7FEC /* DemoObjctvOS */,
317310
6E9681A121EEA3D8009B7FEC /* SharedResources */,
@@ -331,6 +324,15 @@
331324
name = Products;
332325
sourceTree = "<group>";
333326
};
327+
6EFA322A227CDDF0006FA572 /* Samples */ = {
328+
isa = PBXGroup;
329+
children = (
330+
6EFA3204227CD55E006FA572 /* SamplesForAPI.h */,
331+
6EFA3205227CD55E006FA572 /* SamplesForAPI.m */,
332+
);
333+
path = Samples;
334+
sourceTree = "<group>";
335+
};
334336
E4F9C3F25D5A22985B6E41CD /* Frameworks */ = {
335337
isa = PBXGroup;
336338
children = (
@@ -640,9 +642,9 @@
640642
6E9681BA21EEB361009B7FEC /* VariationViewController.m in Sources */,
641643
6EB8456B21EE5DE3005346CC /* AppDelegate.m in Sources */,
642644
6E9681D821EFA5B2009B7FEC /* CustomLogger.m in Sources */,
643-
6E9681BB21EEB361009B7FEC /* FailureViewController.m in Sources */,
645+
646+
6EFA3206227CD55E006FA572 /* SamplesForAPI.m in Sources */,
644647
6E4DD7F721E51E5500B0C2C7 /* main.m in Sources */,
645-
6E9681BC21EEB361009B7FEC /* SplashScreenViewController.m in Sources */,
646648
);
647649
runOnlyForDeploymentPostprocessing = 0;
648650
};
@@ -653,9 +655,8 @@
653655
6E9681BD21EEB364009B7FEC /* VariationViewController.m in Sources */,
654656
6EB8456C21EE5DE3005346CC /* AppDelegate.m in Sources */,
655657
6E9681D921EFA5B2009B7FEC /* CustomLogger.m in Sources */,
656-
6E9681BE21EEB364009B7FEC /* FailureViewController.m in Sources */,
658+
6EFA3207227CD55E006FA572 /* SamplesForAPI.m in Sources */,
657659
6E4DD7F821E51E5600B0C2C7 /* main.m in Sources */,
658-
6E9681BF21EEB364009B7FEC /* SplashScreenViewController.m in Sources */,
659660
);
660661
runOnlyForDeploymentPostprocessing = 0;
661662
};

DemoObjCApp/FailureViewController.m

Lines changed: 0 additions & 29 deletions
This file was deleted.

DemoObjCApp/FailureViewController.h renamed to DemoObjCApp/Samples/SamplesForAPI.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//
12
/****************************************************************************
23
* Copyright 2019, Optimizely, Inc. and contributors *
34
* *
@@ -13,13 +14,16 @@
1314
* See the License for the specific language governing permissions and *
1415
* limitations under the License. *
1516
***************************************************************************/
17+
1618

17-
#import <UIKit/UIKit.h>
19+
#import <Foundation/Foundation.h>
1820

1921
NS_ASSUME_NONNULL_BEGIN
2022

21-
@interface FailureViewController : UIViewController
23+
@class OptimizelyClient;
2224

25+
@interface SamplesForAPI: NSObject
26+
+(void)run:(OptimizelyClient*)optimizely;
2327
@end
2428

2529
NS_ASSUME_NONNULL_END

DemoObjCApp/Samples/SamplesForAPI.m

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
//
2+
/****************************************************************************
3+
* Copyright 2019, Optimizely, Inc. and contributors *
4+
* *
5+
* Licensed under the Apache License, Version 2.0 (the "License"); *
6+
* you may not use this file except in compliance with the License. *
7+
* You may obtain a copy of the License at *
8+
* *
9+
* http://www.apache.org/licenses/LICENSE-2.0 *
10+
* *
11+
* Unless required by applicable law or agreed to in writing, software *
12+
* distributed under the License is distributed on an "AS IS" BASIS, *
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14+
* See the License for the specific language governing permissions and *
15+
* limitations under the License. *
16+
***************************************************************************/
17+
18+
19+
#import "SamplesForAPI.h"
20+
@import Optimizely;
21+
22+
@implementation SamplesForAPI
23+
24+
+(void)run:(OptimizelyClient*)optimizely {
25+
NSDictionary *attributes = @{
26+
@"device": @"iPhone",
27+
@"lifetime": @24738388,
28+
@"is_logged_in": @true
29+
};
30+
31+
NSDictionary *tags = @{
32+
@"category" : @"shoes",
33+
@"count": @5
34+
};
35+
36+
// MARK: - activate
37+
38+
{
39+
NSError *error = nil;
40+
NSString *variationKey = [optimizely activateWithExperimentKey:@"my_experiment_key"
41+
userId:@"user_123"
42+
attributes:attributes
43+
error:&error];
44+
if (variationKey == nil) {
45+
NSLog(@"Error: %@", error);
46+
} else {
47+
NSLog(@"[activate] %@", variationKey);
48+
}
49+
}
50+
51+
// MARK: - getVariationKey
52+
53+
{
54+
NSError *error = nil;
55+
NSString *variationKey = [optimizely getVariationKeyWithExperimentKey:@"my_experiment_key"
56+
userId:@"user_123"
57+
attributes:attributes
58+
error:&error];
59+
if (variationKey == nil) {
60+
NSLog(@"Error: %@", error);
61+
} else {
62+
NSLog(@"[getVariationKey] %@", variationKey);
63+
}
64+
}
65+
66+
// MARK: - getForcedVariation
67+
68+
{
69+
NSString *variationKey = [optimizely getForcedVariationWithExperimentKey:@"my_experiment_key"
70+
userId:@"user_123"];
71+
NSLog(@"[getForcedVariation] %@", variationKey);
72+
}
73+
74+
// MARK: - setForcedVariation
75+
76+
{
77+
BOOL result = [optimizely setForcedVariationWithExperimentKey:@"my_experiment_key"
78+
userId:@"user_123"
79+
variationKey:@"some_variation_key"];
80+
NSLog(@"[setForcedVariation] %d", result);
81+
}
82+
83+
// MARK: - isFeatureEnabled
84+
85+
{
86+
NSError *error = nil;
87+
NSNumber *enabled = [optimizely isFeatureEnabledWithFeatureKey:@"my_feature_key"
88+
userId:@"user_123"
89+
attributes:attributes
90+
error:&error];
91+
92+
if (enabled == nil) {
93+
NSLog(@"Error: %@", error);
94+
} else {
95+
NSLog(@"[isFeatureEnabled] %d", enabled.boolValue);
96+
}
97+
}
98+
99+
// MARK: - getFeatureVariable
100+
101+
{
102+
NSError *error = nil;
103+
NSNumber *featureVariableValue = [optimizely getFeatureVariableDoubleWithFeatureKey:@"my_feature_key"
104+
variableKey:@"double_variable_key"
105+
userId:@"user_123"
106+
attributes:attributes
107+
error:&error];
108+
if (featureVariableValue == nil) {
109+
NSLog(@"Error: %@", error);
110+
} else {
111+
NSLog(@"[getFeatureVariableDouble] %@", featureVariableValue);
112+
}
113+
}
114+
115+
// MARK: - getEnabledFeatures
116+
117+
{
118+
NSError *error = nil;
119+
NSArray *enabledFeatures = [optimizely getEnabledFeaturesWithUserId:@"user_123"
120+
attributes:attributes
121+
error:&error];
122+
if (enabledFeatures == nil) {
123+
NSLog(@"Error: %@", error);
124+
} else {
125+
NSLog(@"[getEnabledFeatures] %@", enabledFeatures);
126+
}
127+
}
128+
129+
// MARK: - track
130+
131+
{
132+
NSError *error = nil;
133+
BOOL success = [optimizely trackWithEventKey:@"my_purchase_event_key"
134+
userId:@"user_123"
135+
attributes:attributes
136+
eventTags:tags
137+
error:&error];
138+
if (success == false) {
139+
NSLog(@"Error: %@", error);
140+
} else {
141+
NSLog(@"[track]");
142+
}
143+
}
144+
145+
}
146+
147+
@end

0 commit comments

Comments
 (0)