Skip to content

Support platforms back to macOS 10.15, iOS 13, tvOS 13, and watchOS 6 #7

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 8 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import PackageDescription
let package = Package(
name: "swift-openapi-urlsession",
platforms: [
.macOS(.v13), .iOS(.v16), .tvOS(.v16), .watchOS(.v9),
.macOS(.v11), .iOS(.v13), .tvOS(.v13), .watchOS(.v6),
],
products: [
.library(
Expand Down
16 changes: 12 additions & 4 deletions Sources/OpenAPIURLSession/URLSessionTransport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,18 @@ public struct URLSessionTransport: ClientTransport {
}

private func invokeSession(_ urlRequest: URLRequest) async throws -> (Data, URLResponse) {
#if canImport(FoundationNetworking)
#if canImport(FoundationNetworking)
return try await performDataTask(with: urlRequest)
#else
if #available(iOS 15.0, *) {
return try await configuration.session.data(for: urlRequest)
} else {
return try await performDataTask(with: urlRequest)
}
#endif
}

private func performDataTask(with urlRequest: URLRequest) async throws -> (Data, URLResponse) {
return try await withCheckedThrowingContinuation { continuation in
configuration.session
.dataTask(with: urlRequest) { data, response, error in
Expand All @@ -104,9 +115,6 @@ public struct URLSessionTransport: ClientTransport {
}
.resume()
}
#else
return try await configuration.session.data(for: urlRequest)
#endif
}
}

Expand Down