From 0469f6d430cb7762c17047fd0eb185a753825bb1 Mon Sep 17 00:00:00 2001 From: tusharkhandelwal8 Date: Thu, 24 Apr 2025 15:13:32 +0530 Subject: [PATCH] Configure ephemeral URLSession for iOS 18.4 simulator to avoid network failures. --- FirebaseRemoteConfig/Sources/RCNConfigFetch.m | 4 +-- .../Sources/RCNConfigURLSession.h | 29 +++++++++++++++++ .../Sources/RCNConfigURLSession.m | 32 +++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 FirebaseRemoteConfig/Sources/RCNConfigURLSession.h create mode 100644 FirebaseRemoteConfig/Sources/RCNConfigURLSession.m diff --git a/FirebaseRemoteConfig/Sources/RCNConfigFetch.m b/FirebaseRemoteConfig/Sources/RCNConfigFetch.m index 3fad2694b02..073b1d7d142 100644 --- a/FirebaseRemoteConfig/Sources/RCNConfigFetch.m +++ b/FirebaseRemoteConfig/Sources/RCNConfigFetch.m @@ -24,6 +24,7 @@ #import "FirebaseRemoteConfig/Sources/RCNConfigConstants.h" #import "FirebaseRemoteConfig/Sources/RCNConfigContent.h" #import "FirebaseRemoteConfig/Sources/RCNConfigExperiment.h" +#import "FirebaseRemoteConfig/Sources/RCNConfigURLSession.h" #import "FirebaseRemoteConfig/Sources/RCNDevice.h" @import FirebaseRemoteConfigInterop; @@ -640,8 +641,7 @@ - (NSString *)constructServerURL { } - (NSURLSession *)newFetchSession { - NSURLSessionConfiguration *config = - [[NSURLSessionConfiguration defaultSessionConfiguration] copy]; + NSURLSessionConfiguration *config = [RCNConfigURLSession RemoteConfigURLSession]; config.timeoutIntervalForRequest = _settings.fetchTimeout; config.timeoutIntervalForResource = _settings.fetchTimeout; NSURLSession *session = [NSURLSession sessionWithConfiguration:config]; diff --git a/FirebaseRemoteConfig/Sources/RCNConfigURLSession.h b/FirebaseRemoteConfig/Sources/RCNConfigURLSession.h new file mode 100644 index 00000000000..16f6009670d --- /dev/null +++ b/FirebaseRemoteConfig/Sources/RCNConfigURLSession.h @@ -0,0 +1,29 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +@interface RCNConfigURLSession : NSObject + +/// Returns an `NSURLSessionConfiguration` instance suitable for Remote Config requests. +/// +/// On iOS 18.4+ and visionOS 2.4+ simulators, this method returns an ephemeral session +/// configuration as a workaround for a network request failure bug. See +/// https://developer.apple.com/forums/thread/777999 for details. For all other environments, the +/// default session configuration is returned. ++ (NSURLSessionConfiguration *)RemoteConfigURLSession; + +@end diff --git a/FirebaseRemoteConfig/Sources/RCNConfigURLSession.m b/FirebaseRemoteConfig/Sources/RCNConfigURLSession.m new file mode 100644 index 00000000000..f7a6eabdeab --- /dev/null +++ b/FirebaseRemoteConfig/Sources/RCNConfigURLSession.m @@ -0,0 +1,32 @@ +/* + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import "RCNConfigURLSession.h" + +@implementation RCNConfigURLSession + ++ (NSURLSessionConfiguration *)RemoteConfigURLSession { + // Check if the current operating system version meets the criteria of the affected simulators. + if (@available(iOS 18.4, tvOS 100.0, watchOS 100.0, visionOS 2.4, *)) { + // If the app is running on one of the affected simulator versions (or later for iOS and + // visionOS), use an ephemeral session configuration. Ephemeral sessions do not persist caches, + // cookies, or credential data to disk, which circumvents the known bug. + return [[NSURLSessionConfiguration ephemeralSessionConfiguration] copy]; + } + return [[NSURLSessionConfiguration defaultSessionConfiguration] copy]; +} + +@end