Skip to content

Commit c6486f9

Browse files
set minimum TSL (#338)
1 parent b238292 commit c6486f9

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

OptimizelyDemoApp/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3636

3737
// customizable settings
3838
let datafileName = "demoTestDatafile" // default parameter for initializing Optimizely from saved datafile
39-
var projectId = "11093712109" // project name: X Mobile - Sample App
39+
var projectId:String? // project name: X Mobile - Sample App
4040
var experimentKey = "background_experiment"
4141
var eventKey = "sample_conversion"
4242
let attributes = ["sample_attribute_key":"sample_attribute_value"]

OptimizelySDKCore/OptimizelySDKCore/OPTLYHTTPRequestManager.m

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
@interface OPTLYHTTPRequestManager()
2828

29+
- (NSURLSession *)session;
30+
2931
// Use this flag to deterine if we are running a unit test
3032
// The flag is needed to track some values for unit test
3133
@property (nonatomic, assign) BOOL isRunningTest;
@@ -35,6 +37,13 @@ @interface OPTLYHTTPRequestManager()
3537

3638
@implementation OPTLYHTTPRequestManager
3739

40+
- (NSURLSession *)session {
41+
NSURLSession *ephemeralSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration]];
42+
ephemeralSession.configuration.TLSMinimumSupportedProtocol = kTLSProtocol12;
43+
44+
return ephemeralSession;
45+
}
46+
3847
# pragma mark - Object Initializers
3948

4049
- (id)init
@@ -83,9 +92,9 @@ - (void)GETWithParameters:(NSDictionary *)parameters
8392
url:(NSURL *)url
8493
completionHandler:(OPTLYHTTPRequestManagerResponse)completion
8594
{
86-
NSURLSession *ephemeralSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration]];
95+
8796
NSURL *urlWithParameterQuery = [self buildQueryURL:url withParameters:parameters];
88-
NSURLSessionDataTask *downloadTask = [ephemeralSession dataTaskWithURL:urlWithParameterQuery
97+
NSURLSessionDataTask *downloadTask = [self.session dataTaskWithURL:urlWithParameterQuery
8998
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
9099
if (completion) {
91100
completion(data, response, error);
@@ -178,8 +187,7 @@ - (void)GETIfModifiedSince:(NSString *)lastModifiedDate
178187
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
179188
[request setValue:lastModifiedDate forHTTPHeaderField:@"If-Modified-Since"];
180189

181-
NSURLSession *ephemeralSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration]];
182-
NSURLSessionDataTask *dataTask = [ephemeralSession dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
190+
NSURLSessionDataTask *dataTask = [self.session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
183191
if (completion) {
184192
completion(data, response, error);
185193
}
@@ -272,7 +280,6 @@ - (void)POSTWithParameters:(NSDictionary *)parameters
272280
url:(NSURL *)url
273281
completionHandler:(OPTLYHTTPRequestManagerResponse)completion
274282
{
275-
NSURLSession *ephemeralSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration]];
276283
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
277284
[request setHTTPMethod:kHTTPRequestMethodPost];
278285

@@ -288,7 +295,7 @@ - (void)POSTWithParameters:(NSDictionary *)parameters
288295

289296
[request addValue:kHTTPHeaderFieldValueApplicationJSON forHTTPHeaderField:kHTTPHeaderFieldContentType];
290297

291-
NSURLSessionUploadTask *uploadTask = [ephemeralSession uploadTaskWithRequest:request
298+
NSURLSessionUploadTask *uploadTask = [self.session uploadTaskWithRequest:request
292299
fromData:data
293300
completionHandler:^(NSData *data,NSURLResponse *response,NSError *error) {
294301
if (completion) {

0 commit comments

Comments
 (0)