Skip to content
2 changes: 2 additions & 0 deletions FirebaseVertexAI/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
Note: This feature is in Public Preview and relies on experimental models,
which means that it is not subject to any SLA or deprecation policy and could
change in backwards-incompatible ways.
- [fixed] Fixed an issue where network requests would fail in the iOS 18.4
simulator due to a `URLSession` bug introduced in Xcode 16.3. (#14677)

# 11.11.0
- [added] Emits a warning when attempting to use an incompatible model with
Expand Down
38 changes: 38 additions & 0 deletions FirebaseVertexAI/Sources/GenAIURLSession.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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

/// A namespace providing `URLSession` instances.
enum GenAIURLSession {
/// The default `URLSession` instance for the SDK; returns `URLSession.shared` by default.
///
/// - Important: On affected simulators (iOS 18.4+, visionOS 2.4+), this returns an ephemeral
/// `URLSession` instance as a workaround for a known system bug.
static let `default` = {
#if targetEnvironment(simulator)
// The iOS 18.4 and visionOS 2.4 simulators (included in Xcode 16.3) contain a bug in
// `URLSession` causing requests to fail. The following workaround, using an ephemeral session
// resolves the issue. See https://developer.apple.com/forums/thread/777999 for more details.
//
// Note: This bug only impacts the simulator, not real devices, and does not impact watchOS
// or tvOS.
if #available(iOS 18.4, tvOS 100.0, watchOS 100.0, visionOS 2.4, *) {
return URLSession(configuration: URLSessionConfiguration.ephemeral)
}
#endif // targetEnvironment(simulator)

return URLSession.shared
}()
}
2 changes: 1 addition & 1 deletion FirebaseVertexAI/Sources/GenerativeModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public final class GenerativeModel: Sendable {
toolConfig: ToolConfig? = nil,
systemInstruction: ModelContent? = nil,
requestOptions: RequestOptions,
urlSession: URLSession = .shared) {
urlSession: URLSession = GenAIURLSession.default) {
self.modelName = modelName
self.modelResourceName = modelResourceName
self.apiConfig = apiConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public final class ImagenModel {
generationConfig: ImagenGenerationConfig?,
safetySettings: ImagenSafetySettings?,
requestOptions: RequestOptions,
urlSession: URLSession = .shared) {
urlSession: URLSession = GenAIURLSession.default) {
self.modelResourceName = modelResourceName
self.apiConfig = apiConfig
generativeAIService = GenerativeAIService(
Expand Down