Skip to content

Commit

Permalink
Merge pull request #359 from Countly/NSURLConfiguration
Browse files Browse the repository at this point in the history
Applied URLSessionConfiguration to non-queued requests
  • Loading branch information
turtledreams authored Nov 14, 2024
2 parents dc89900 + c2ea9fa commit e41fd14
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions CountlyCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ void CountlyPrint(NSString *stringToPrint);
- (void)recordOrientation;

- (BOOL)hasStarted_;

- (NSURLSession *)URLSession;
@end


Expand Down
12 changes: 12 additions & 0 deletions CountlyCommon.m
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion CountlyFeedbackWidget.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions CountlyFeedbacksInternal.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -425,7 +425,7 @@ - (void)getFeedbackWidgets:(void (^)(NSArray <CountlyFeedbackWidget *> *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;

Expand Down
3 changes: 2 additions & 1 deletion CountlyNotificationService.m
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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)
{
Expand Down
8 changes: 4 additions & 4 deletions CountlyRemoteConfigInternal.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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<NSString*, CountlyExperimentInformation*> * experiments = NSMutableDictionary.new;
Expand Down
2 changes: 1 addition & 1 deletion CountlyServerConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit e41fd14

Please sign in to comment.