Skip to content
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

Allow providing custom URLSession used internally for network requests #216

Merged
merged 2 commits into from
Dec 13, 2024
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
6 changes: 5 additions & 1 deletion Sources/TelemetryDeck/Signals/Signal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,11 @@ extension DefaultSignalPayload {
#if os(iOS) || os(tvOS)
return UIApplication.shared.userInterfaceLayoutDirection == .leftToRight ? "leftToRight" : "rightToLeft"
#elseif os(macOS)
return NSApp.userInterfaceLayoutDirection == .leftToRight ? "leftToRight" : "rightToLeft"
if let nsApp = NSApp {
return nsApp.userInterfaceLayoutDirection == .leftToRight ? "leftToRight" : "rightToLeft"
} else {
return "N/A"
}
#else
return "N/A"
#endif
Expand Down
2 changes: 1 addition & 1 deletion Sources/TelemetryDeck/Signals/SignalManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private extension SignalManager {
self.configuration.logHandler?.log(.debug, message: messageString)
}

let task = URLSession.shared.dataTask(with: urlRequest, completionHandler: completionHandler)
let task = self.configuration.urlSession.dataTask(with: urlRequest, completionHandler: completionHandler)
task.resume()
}
}
Expand Down
7 changes: 7 additions & 0 deletions Sources/TelemetryDeck/TelemetryClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ public final class TelemetryManagerConfiguration: @unchecked Sendable {
}
}

/// A customizable `URLSession` used for network requests within TelemetryDeck.
///
/// This property allows you to override the default `URLSession.shared` for cases where
/// a custom session configuration is needed (e.g., for network interception, caching strategies,
/// or debugging). If not set, the `URLSession.shared` instance will be used.
public var urlSession: URLSession = URLSession.shared

@available(*, deprecated, message: "Please use the testMode property instead")
public var sendSignalsInDebugConfiguration: Bool = false

Expand Down
Loading