Skip to content

Commit c0b399e

Browse files
authored
[Vertex AI] Use ephemeral URLSession config on iOS 18.4 sim (#14696)
1 parent fe90cd6 commit c0b399e

File tree

9 files changed

+56
-18
lines changed

9 files changed

+56
-18
lines changed

.github/workflows/vertexai.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,22 @@ jobs:
4747
xcode: Xcode_16.2
4848
target: iOS
4949
- os: macos-15
50-
xcode: Xcode_16.2
50+
xcode: Xcode_16.3
5151
target: iOS
5252
- os: macos-15
53-
xcode: Xcode_16.2
53+
xcode: Xcode_16.3
5454
target: tvOS
5555
- os: macos-15
56-
xcode: Xcode_16.2
56+
xcode: Xcode_16.3
5757
target: macOS
5858
- os: macos-15
59-
xcode: Xcode_16.2
59+
xcode: Xcode_16.3
6060
target: watchOS
6161
- os: macos-15
62-
xcode: Xcode_16.2
62+
xcode: Xcode_16.3
6363
target: catalyst
6464
- os: macos-15
65-
xcode: Xcode_16.2
65+
xcode: Xcode_16.3
6666
target: visionOS
6767
runs-on: ${{ matrix.os }}
6868
needs: spm-package-resolved
@@ -98,7 +98,7 @@ jobs:
9898
os: [macos-15]
9999
include:
100100
- os: macos-15
101-
xcode: Xcode_16.2
101+
xcode: Xcode_16.3
102102
runs-on: ${{ matrix.os }}
103103
needs: spm-package-resolved
104104
env:
@@ -137,11 +137,11 @@ jobs:
137137
swift_version: 5.9
138138
warnings:
139139
- os: macos-15
140-
xcode: Xcode_16.2
140+
xcode: Xcode_16.3
141141
swift_version: 5.9
142142
warnings:
143143
- os: macos-15
144-
xcode: Xcode_16.2
144+
xcode: Xcode_16.3
145145
swift_version: 6.0
146146
warnings:
147147
runs-on: ${{ matrix.os }}

FirebaseVertexAI/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
change in backwards-incompatible ways.
99
- [added] Added support for specifying the minimum and maximum number of items
1010
(`minItems` / `maxItems`) to generate in an array `Schema`. (#14671)
11+
- [fixed] Fixed an issue where network requests would fail in the iOS 18.4
12+
simulator due to a `URLSession` bug introduced in Xcode 16.3. (#14677)
1113

1214
# 11.11.0
1315
- [added] Emits a warning when attempting to use an incompatible model with
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import Foundation
16+
17+
/// A namespace providing `URLSession` instances.
18+
enum GenAIURLSession {
19+
/// The default `URLSession` instance for the SDK; returns `URLSession.shared` by default.
20+
///
21+
/// - Important: On affected simulators (iOS 18.4+, visionOS 2.4+), this returns an ephemeral
22+
/// `URLSession` instance as a workaround for a known system bug.
23+
static let `default` = {
24+
#if targetEnvironment(simulator)
25+
// The iOS 18.4 and visionOS 2.4 simulators (included in Xcode 16.3) contain a bug in
26+
// `URLSession` causing requests to fail. The following workaround, using an ephemeral session
27+
// resolves the issue. See https://developer.apple.com/forums/thread/777999 for more details.
28+
//
29+
// Note: This bug only impacts the simulator, not real devices, and does not impact watchOS
30+
// or tvOS.
31+
if #available(iOS 18.4, tvOS 100.0, watchOS 100.0, visionOS 2.4, *) {
32+
return URLSession(configuration: URLSessionConfiguration.ephemeral)
33+
}
34+
#endif // targetEnvironment(simulator)
35+
36+
return URLSession.shared
37+
}()
38+
}

FirebaseVertexAI/Sources/GenerativeModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public final class GenerativeModel: Sendable {
8383
toolConfig: ToolConfig? = nil,
8484
systemInstruction: ModelContent? = nil,
8585
requestOptions: RequestOptions,
86-
urlSession: URLSession = .shared) {
86+
urlSession: URLSession = GenAIURLSession.default) {
8787
self.modelName = modelName
8888
self.modelResourceName = modelResourceName
8989
self.apiConfig = apiConfig

FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public final class ImagenModel {
5353
generationConfig: ImagenGenerationConfig?,
5454
safetySettings: ImagenSafetySettings?,
5555
requestOptions: RequestOptions,
56-
urlSession: URLSession = .shared) {
56+
urlSession: URLSession = GenAIURLSession.default) {
5757
self.modelResourceName = modelResourceName
5858
self.apiConfig = apiConfig
5959
generativeAIService = GenerativeAIService(

FirebaseVertexAI/Sources/VertexAI.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import FirebaseCore
1818
import Foundation
1919

2020
// Avoids exposing internal FirebaseCore APIs to Swift users.
21-
@_implementationOnly import FirebaseCoreExtension
21+
internal import FirebaseCoreExtension
2222

2323
/// The Vertex AI for Firebase SDK provides access to Gemini models directly from your app.
2424
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)

FirebaseVertexAI/Sources/VertexLog.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import Foundation
1616
import os.log
1717

18-
@_implementationOnly import FirebaseCoreExtension
18+
internal import FirebaseCoreExtension
1919

2020
enum VertexLog {
2121
/// Log message codes for the Vertex AI SDK

FirebaseVertexAI/Tests/Unit/GenerativeModelTests.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import FirebaseAuthInterop
1717
import FirebaseCore
1818
import XCTest
1919

20-
@testable import FirebaseVertexAI
20+
@testable public import FirebaseVertexAI
2121

2222
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
2323
final class GenerativeModelTests: XCTestCase {
@@ -1690,8 +1690,7 @@ struct AppCheckErrorFake: Error {}
16901690

16911691
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
16921692
extension SafetyRating: Swift.Comparable {
1693-
public static func < (lhs: FirebaseVertexAI.SafetyRating,
1694-
rhs: FirebaseVertexAI.SafetyRating) -> Bool {
1693+
public static func < (lhs: SafetyRating, rhs: SafetyRating) -> Bool {
16951694
return lhs.category.rawValue < rhs.category.rawValue
16961695
}
16971696
}

FirebaseVertexAI/Tests/Unit/VertexComponentTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
// limitations under the License.
1414

1515
@preconcurrency import FirebaseCore
16+
internal import FirebaseCoreExtension
1617
import Foundation
1718
import XCTest
1819

19-
@_implementationOnly import FirebaseCoreExtension
20-
2120
@testable import FirebaseVertexAI
2221

2322
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)

0 commit comments

Comments
 (0)