From 9979dd20347f9403fa1c0c53bb2e747ede40427c Mon Sep 17 00:00:00 2001 From: cat Date: Fri, 29 Mar 2024 06:47:38 +0800 Subject: [PATCH] fix: Variable name 'DarwinVersion' should start with a lowercase character & device for mac --- Sources/Network/UserAgent.swift | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Sources/Network/UserAgent.swift b/Sources/Network/UserAgent.swift index e53e3f1..4d6e713 100644 --- a/Sources/Network/UserAgent.swift +++ b/Sources/Network/UserAgent.swift @@ -6,10 +6,13 @@ // import Foundation +#if os(iOS) import UIKit - +#elseif os(macOS) +import AppKit +#endif // eg. Darwin/16.3.0 -var DarwinVersion: String { +var darwinVersion: String { var sysinfo = utsname() uname(&sysinfo) let dv = String(bytes: Data(bytes: &sysinfo.release, count: Int(_SYS_NAMELEN)), encoding: .ascii)!.trimmingCharacters(in: .controlCharacters) @@ -25,8 +28,14 @@ var CFNetworkVersion: String { // eg. iOS/10_1 var deviceVersion: String { +#if os(iOS) let currentDevice = UIDevice.current return "\(currentDevice.systemName)/\(currentDevice.systemVersion)" +#elseif os(macOS) + let info = ProcessInfo.processInfo + return "macOS/\(info.operatingSystemVersion.majorVersion).\(info.operatingSystemVersion.minorVersion).\(info.operatingSystemVersion.patchVersion)" +#endif + } // eg. iPhone5,2 @@ -46,4 +55,4 @@ var appNameAndVersion: String { return "\(name)/\(version)" } -let userAgent = "\(appNameAndVersion) \(deviceName) \(deviceVersion) \(CFNetworkVersion) \(DarwinVersion)" +let userAgent = "\(appNameAndVersion) \(deviceName) \(deviceVersion) \(CFNetworkVersion) \(darwinVersion)"