Skip to content

Commit

Permalink
Merge pull request #216 from TelemetryDeck/feature/custom-urlsession
Browse files Browse the repository at this point in the history
Allow providing custom URLSession used internally for network requests
  • Loading branch information
Jeehut authored Dec 13, 2024
2 parents 359a1df + b6ef799 commit b5fc168
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
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

0 comments on commit b5fc168

Please sign in to comment.