From ffc8780dd82e21f2d88d6cec7ecf4c09bc36ea9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihat=20Gu=CC=88ndu=CC=88z?= Date: Fri, 13 Dec 2024 10:07:03 +0100 Subject: [PATCH 1/2] Allow providing custom URLSession used internally for network requests Fixes https://github.com/TelemetryDeck/SwiftSDK/issues/215 --- Sources/TelemetryDeck/Signals/SignalManager.swift | 2 +- Sources/TelemetryDeck/TelemetryClient.swift | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Sources/TelemetryDeck/Signals/SignalManager.swift b/Sources/TelemetryDeck/Signals/SignalManager.swift index bf80dfa..20ff12b 100644 --- a/Sources/TelemetryDeck/Signals/SignalManager.swift +++ b/Sources/TelemetryDeck/Signals/SignalManager.swift @@ -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() } } diff --git a/Sources/TelemetryDeck/TelemetryClient.swift b/Sources/TelemetryDeck/TelemetryClient.swift index cd0b052..c83389f 100644 --- a/Sources/TelemetryDeck/TelemetryClient.swift +++ b/Sources/TelemetryDeck/TelemetryClient.swift @@ -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 From b6ef7990a2a82fab34c1742246d5e74be2e1a8e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihat=20Gu=CC=88ndu=CC=88z?= Date: Fri, 13 Dec 2024 10:16:05 +0100 Subject: [PATCH 2/2] Fix a potential source for crashes on macOS when detecting layout direction --- Sources/TelemetryDeck/Signals/Signal.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sources/TelemetryDeck/Signals/Signal.swift b/Sources/TelemetryDeck/Signals/Signal.swift index 6727529..d95f6e1 100644 --- a/Sources/TelemetryDeck/Signals/Signal.swift +++ b/Sources/TelemetryDeck/Signals/Signal.swift @@ -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