Skip to content

RC Configure ephemeral URLSession for iOS 18.4 simulator #14768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions FirebaseRemoteConfig/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
3 changes: 2 additions & 1 deletion FirebaseRemoteConfig/Sources/RCNConfigFetch.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -641,7 +642,7 @@ - (NSString *)constructServerURL {

- (NSURLSession *)newFetchSession {
NSURLSessionConfiguration *config =
[[NSURLSessionConfiguration defaultSessionConfiguration] copy];
[RCNConfigSessionConfiguration remoteConfigSessionConfiguration];
config.timeoutIntervalForRequest = _settings.fetchTimeout;
config.timeoutIntervalForResource = _settings.fetchTimeout;
NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
Expand Down
29 changes: 29 additions & 0 deletions FirebaseRemoteConfig/Sources/RCNConfigSessionConfiguration.h
Original file line number Diff line number Diff line change
@@ -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 changes: 32 additions & 0 deletions FirebaseRemoteConfig/Sources/RCNConfigSessionConfiguration.m
Original file line number Diff line number Diff line change
@@ -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
Loading