From 0ded0386a1cfc86c0c4ec43ca26ca7af34d75a80 Mon Sep 17 00:00:00 2001 From: ijunaid Date: Wed, 13 Nov 2024 17:39:30 +0500 Subject: [PATCH 1/2] Applied URLSessionConfiguration to non-queued requests --- CountlyCommon.h | 2 ++ CountlyCommon.m | 12 ++++++++++++ CountlyFeedbackWidget.m | 2 +- CountlyFeedbacksInternal.m | 4 ++-- CountlyNotificationService.m | 3 ++- CountlyRemoteConfigInternal.m | 8 ++++---- CountlyServerConfig.m | 2 +- 7 files changed, 24 insertions(+), 9 deletions(-) diff --git a/CountlyCommon.h b/CountlyCommon.h index 2aaf4e66..08ad66f5 100644 --- a/CountlyCommon.h +++ b/CountlyCommon.h @@ -122,6 +122,8 @@ void CountlyPrint(NSString *stringToPrint); - (void)recordOrientation; - (BOOL)hasStarted_; + +- (NSURLSession *)URLSession; @end diff --git a/CountlyCommon.m b/CountlyCommon.m index 20db5c3f..1017d2c2 100644 --- a/CountlyCommon.m +++ b/CountlyCommon.m @@ -317,6 +317,18 @@ - (void)tryPresentingViewController:(UIViewController *)viewController withCompl } #endif +- (NSURLSession *)URLSession +{ + if (CountlyConnectionManager.sharedInstance.URLSessionConfiguration) + { + return [NSURLSession sessionWithConfiguration:CountlyConnectionManager.sharedInstance.URLSessionConfiguration]; + } + else + { + return NSURLSession.sharedSession; + } +} + @end diff --git a/CountlyFeedbackWidget.m b/CountlyFeedbackWidget.m index 7631dd69..258f265a 100644 --- a/CountlyFeedbackWidget.m +++ b/CountlyFeedbackWidget.m @@ -115,7 +115,7 @@ - (void)getWidgetData:(void (^)(NSDictionary * __nullable widgetData, NSError * return; } - NSURLSessionTask* task = [NSURLSession.sharedSession dataTaskWithRequest:[self dataRequest] completionHandler:^(NSData* data, NSURLResponse* response, NSError* error) + NSURLSessionTask* task = [CountlyCommon.sharedInstance.URLSession dataTaskWithRequest:[self dataRequest] completionHandler:^(NSData* data, NSURLResponse* response, NSError* error) { NSDictionary *widgetData = nil; diff --git a/CountlyFeedbacksInternal.m b/CountlyFeedbacksInternal.m index 4a7bb9e2..6b320811 100644 --- a/CountlyFeedbacksInternal.m +++ b/CountlyFeedbacksInternal.m @@ -252,7 +252,7 @@ - (void)presentRatingWidgetWithID:(NSString *)widgetID closeButtonText:(NSString return; NSURLRequest* feedbackWidgetCheckRequest = [self widgetCheckURLRequest:widgetID]; - NSURLSessionTask* task = [NSURLSession.sharedSession dataTaskWithRequest:feedbackWidgetCheckRequest completionHandler:^(NSData* data, NSURLResponse* response, NSError* error) + NSURLSessionTask* task = [CountlyCommon.sharedInstance.URLSession dataTaskWithRequest:feedbackWidgetCheckRequest completionHandler:^(NSData* data, NSURLResponse* response, NSError* error) { NSDictionary* widgetInfo = nil; @@ -425,7 +425,7 @@ - (void)getFeedbackWidgets:(void (^)(NSArray *feedback if (CountlyDeviceInfo.sharedInstance.isDeviceIDTemporary) return; - NSURLSessionTask* task = [NSURLSession.sharedSession dataTaskWithRequest:[self feedbacksRequest] completionHandler:^(NSData* data, NSURLResponse* response, NSError* error) + NSURLSessionTask* task = [CountlyCommon.sharedInstance.URLSession dataTaskWithRequest:[self feedbacksRequest] completionHandler:^(NSData* data, NSURLResponse* response, NSError* error) { NSDictionary *feedbacksResponse = nil; diff --git a/CountlyNotificationService.m b/CountlyNotificationService.m index a42a08ad..87841808 100644 --- a/CountlyNotificationService.m +++ b/CountlyNotificationService.m @@ -5,6 +5,7 @@ // Please visit www.count.ly for more information. #import "CountlyNotificationService.h" +#import "CountlyCommon.h" #if DEBUG #define COUNTLY_EXT_LOG(fmt, ...) NSLog([@"%@ " stringByAppendingString:fmt], @"[CountlyNSE]", ##__VA_ARGS__) @@ -85,7 +86,7 @@ + (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withConte COUNTLY_EXT_LOG(@"Attachment specified in Countly payload: %@", attachmentURL); - [[NSURLSession.sharedSession downloadTaskWithURL:[NSURL URLWithString:attachmentURL] completionHandler:^(NSURL * location, NSURLResponse * response, NSError * error) + [[CountlyCommon.sharedInstance.URLSession downloadTaskWithURL:[NSURL URLWithString:attachmentURL] completionHandler:^(NSURL * location, NSURLResponse * response, NSError * error) { if (!error) { diff --git a/CountlyRemoteConfigInternal.m b/CountlyRemoteConfigInternal.m index dd2ed7a8..5e0aee79 100644 --- a/CountlyRemoteConfigInternal.m +++ b/CountlyRemoteConfigInternal.m @@ -197,7 +197,7 @@ - (void)fetchRemoteConfigForKeys:(NSArray *)keys omitKeys:(NSArray *)omitKeys i return; NSURLRequest* request = [self remoteConfigRequestForKeys:keys omitKeys:omitKeys isLegacy:isLegacy]; - NSURLSessionTask* task = [NSURLSession.sharedSession dataTaskWithRequest:request completionHandler:^(NSData* data, NSURLResponse* response, NSError* error) + NSURLSessionTask* task = [CountlyCommon.sharedInstance.URLSession dataTaskWithRequest:request completionHandler:^(NSData* data, NSURLResponse* response, NSError* error) { NSDictionary* remoteConfig = nil; @@ -496,7 +496,7 @@ - (void)testingDownloadAllVariantsInternal:(void (^)(CLYRequestResult response, return; NSURLRequest* request = [self downloadVariantsRequest]; - NSURLSessionTask* task = [NSURLSession.sharedSession dataTaskWithRequest:request completionHandler:^(NSData* data, NSURLResponse* response, NSError* error) + NSURLSessionTask* task = [CountlyCommon.sharedInstance.URLSession dataTaskWithRequest:request completionHandler:^(NSData* data, NSURLResponse* response, NSError* error) { NSMutableDictionary* variants = NSMutableDictionary.new; @@ -607,7 +607,7 @@ - (void)testingEnrollIntoVariantInternal:(NSString *)key variantName:(NSString * } NSURLRequest* request = [self enrollInVarianRequestForKey:key variantName:variantName]; - NSURLSessionTask* task = [NSURLSession.sharedSession dataTaskWithRequest:request completionHandler:^(NSData* data, NSURLResponse* response, NSError* error) + NSURLSessionTask* task = [CountlyCommon.sharedInstance.URLSession dataTaskWithRequest:request completionHandler:^(NSData* data, NSURLResponse* response, NSError* error) { NSDictionary* variants = nil; [self clearCachedRemoteConfig]; @@ -721,7 +721,7 @@ - (void)testingDownloaExperimentInfoInternal:(void (^)(CLYRequestResult response return; NSURLRequest* request = [self downloadExperimentInfoRequest]; - NSURLSessionTask* task = [NSURLSession.sharedSession dataTaskWithRequest:request completionHandler:^(NSData* data, NSURLResponse* response, NSError* error) + NSURLSessionTask* task = [CountlyCommon.sharedInstance.URLSession dataTaskWithRequest:request completionHandler:^(NSData* data, NSURLResponse* response, NSError* error) { NSMutableDictionary * experiments = NSMutableDictionary.new; diff --git a/CountlyServerConfig.m b/CountlyServerConfig.m index 300f14e7..c8c93623 100644 --- a/CountlyServerConfig.m +++ b/CountlyServerConfig.m @@ -84,7 +84,7 @@ - (void)fetchServerConfig if (CountlyDeviceInfo.sharedInstance.isDeviceIDTemporary) return; - NSURLSessionTask* task = [NSURLSession.sharedSession dataTaskWithRequest:[self serverConfigRequest] completionHandler:^(NSData* data, NSURLResponse* response, NSError* error) + NSURLSessionTask* task = [CountlyCommon.sharedInstance.URLSession dataTaskWithRequest:[self serverConfigRequest] completionHandler:^(NSData* data, NSURLResponse* response, NSError* error) { NSDictionary *serverConfigResponse = nil; From c2ea9fae9f1d5c726564bf29a492873ab3d0f72f Mon Sep 17 00:00:00 2001 From: turtledreams <62231246+turtledreams@users.noreply.github.com> Date: Thu, 14 Nov 2024 22:00:25 +0900 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a67eec0..3f8d3e68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## XX.XX.XX * Mitigated an issue where visibility could have been wrongly assigned if a view was closed while going to background. (Experimental!) +* Mitigated an issue where the user provided URLSessionConfiguration was not applied to direct requests ## 24.7.7 * Changed the visibility tracking segmentation values to binary