diff --git a/Sources/TelemetryClient/Signal.swift b/Sources/TelemetryClient/Signal.swift index 8c6087f..2ef3e39 100644 --- a/Sources/TelemetryClient/Signal.swift +++ b/Sources/TelemetryClient/Signal.swift @@ -113,7 +113,10 @@ extension DefaultSignalPayload { /// The operating system and its version static var systemVersion: String { - return "\(platform) \(ProcessInfo.processInfo.operatingSystemVersion.majorVersion).\(ProcessInfo.processInfo.operatingSystemVersion.minorVersion).\(ProcessInfo.processInfo.operatingSystemVersion.patchVersion)" + let majorVersion = ProcessInfo.processInfo.operatingSystemVersion.majorVersion + let minorVersion = ProcessInfo.processInfo.operatingSystemVersion.minorVersion + let patchVersion = ProcessInfo.processInfo.operatingSystemVersion.patchVersion + return "\(platform) \(majorVersion).\(minorVersion).\(patchVersion)" } /// The major system version, i.e. iOS 15 @@ -123,7 +126,9 @@ extension DefaultSignalPayload { /// The major system version, i.e. iOS 15 static var majorMinorSystemVersion: String { - return "\(platform) \(ProcessInfo.processInfo.operatingSystemVersion.majorVersion).\(ProcessInfo.processInfo.operatingSystemVersion.minorVersion)" + let majorVersion = ProcessInfo.processInfo.operatingSystemVersion.majorVersion + let minorVersion = ProcessInfo.processInfo.operatingSystemVersion.minorVersion + return "\(platform) \(majorVersion).\(minorVersion)" } /// The Bundle Short Version String, as described in Info.plist diff --git a/Sources/TelemetryClient/SignalCache.swift b/Sources/TelemetryClient/SignalCache.swift index 3ee73bb..74e891c 100644 --- a/Sources/TelemetryClient/SignalCache.swift +++ b/Sources/TelemetryClient/SignalCache.swift @@ -53,12 +53,14 @@ internal class SignalCache where T: Codable { } private func fileURL() -> URL { + // swiftlint:disable force_try let cacheFolderURL = try! FileManager.default.url( for: .cachesDirectory, in: .userDomainMask, appropriateFor: nil, create: false ) + // swiftlint:enable force_try return cacheFolderURL.appendingPathComponent("telemetrysignalcache") } diff --git a/Sources/TelemetryClient/SignalManager.swift b/Sources/TelemetryClient/SignalManager.swift index d4a3732..c81464d 100644 --- a/Sources/TelemetryClient/SignalManager.swift +++ b/Sources/TelemetryClient/SignalManager.swift @@ -68,7 +68,13 @@ internal class SignalManager: SignalManageable { } /// Adds a signal to the process queue - func processSignal(_ signalType: TelemetrySignalType, for clientUser: String? = nil, floatValue: Double? = nil, with additionalPayload: [String: String] = [:], configuration: TelemetryManagerConfiguration) { + func processSignal( + _ signalType: TelemetrySignalType, + for clientUser: String? = nil, + floatValue: Double? = nil, + with additionalPayload: [String: String] = [:], + configuration: TelemetryManagerConfiguration + ) { DispatchQueue.global(qos: .utility).async { let enrichedMetadata: [String: String] = configuration.metadataEnrichers .map { $0.enrich(signalType: signalType, for: clientUser, floatValue: floatValue) } @@ -179,7 +185,11 @@ private extension SignalManager { urlRequest.httpMethod = "POST" urlRequest.addValue("application/json", forHTTPHeaderField: "Content-Type") - urlRequest.httpBody = try! JSONEncoder.telemetryEncoder.encode(signalPostBodies) + guard let body = try? JSONEncoder.telemetryEncoder.encode(signalPostBodies) else { + return + } + + urlRequest.httpBody = body self.configuration.logHandler?.log(.debug, message: String(data: urlRequest.httpBody!, encoding: .utf8)!) let task = URLSession.shared.dataTask(with: urlRequest, completionHandler: completionHandler) @@ -221,7 +231,9 @@ private extension SignalManager { } #else #if DEBUG - configuration.logHandler?.log(message: "[Telemetry] On this platform, Telemetry can't generate a unique user identifier. It is recommended you supply one yourself. More info: https://telemetrydeck.com/pages/signal-reference.html") + let line1 = "[Telemetry] On this platform, Telemetry can't generate a unique user identifier." + let line2 = "It is recommended you supply one yourself. More info: https://telemetrydeck.com/pages/signal-reference.html" + configuration.logHandler?.log(message: "\(line1) \(line2)") #endif return "unknown user \(DefaultSignalPayload.platform) \(DefaultSignalPayload.systemVersion) \(DefaultSignalPayload.buildNumber)" #endif