Browse Source

RC Configure ephemeral URLSession for iOS 18.4 simulator (#14768)

Tushar Khandelwal 11 tháng trước cách đây
mục cha
commit
1c1680713f

+ 4 - 0
FirebaseRemoteConfig/CHANGELOG.md

@@ -1,3 +1,7 @@
+# Unreleased
+- [fixed] Fix an issue where network requests would fail in the iOS 18.4
+  simulator due to a URLSession bug introduced in Xcode 16.3. (#14728)
+
 # 11.10.0
 - [fixed] Fix intermittent `RCNConfigRealtime` crash due to incorrect parsing of fragmented JSON. (#14518)
 

+ 2 - 1
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/RCNConfigSessionConfiguration.h"
 #import "FirebaseRemoteConfig/Sources/RCNDevice.h"
 @import FirebaseRemoteConfigInterop;
 
@@ -641,7 +642,7 @@ static NSInteger const kRCNFetchResponseHTTPStatusCodeGatewayTimeout = 504;
 
 - (NSURLSession *)newFetchSession {
   NSURLSessionConfiguration *config =
-      [[NSURLSessionConfiguration defaultSessionConfiguration] copy];
+      [RCNConfigSessionConfiguration remoteConfigSessionConfiguration];
   config.timeoutIntervalForRequest = _settings.fetchTimeout;
   config.timeoutIntervalForResource = _settings.fetchTimeout;
   NSURLSession *session = [NSURLSession sessionWithConfiguration:config];

+ 29 - 0
FirebaseRemoteConfig/Sources/RCNConfigSessionConfiguration.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 <Foundation/Foundation.h>
+
+@interface RCNConfigSessionConfiguration : 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 *)remoteConfigSessionConfiguration;
+
+@end

+ 32 - 0
FirebaseRemoteConfig/Sources/RCNConfigSessionConfiguration.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 "FirebaseRemoteConfig/Sources/RCNConfigSessionConfiguration.h"
+
+@implementation RCNConfigSessionConfiguration
+
++ (NSURLSessionConfiguration *)remoteConfigSessionConfiguration {
+  // 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];
+  }
+  return [NSURLSessionConfiguration defaultSessionConfiguration];
+}
+
+@end