Skip to content

Commit

Permalink
Simplify system version recoginition code
Browse files Browse the repository at this point in the history
  • Loading branch information
winsmith committed Oct 21, 2021
1 parent d550374 commit 7b3f436
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions Sources/TelemetryClient/Signal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ internal struct SignalPayload: Codable {
var platform: String = Self.platform
var systemVersion: String = Self.systemVersion
var majorSystemVersion: String = Self.majorSystemVersion
var majorMinorSystemVersion: String = Self.majorMinorSystemVersion
var appVersion: String = Self.appVersion
var buildNumber: String = Self.buildNumber
var isSimulator: String = "\(Self.isSimulator)"
Expand Down Expand Up @@ -115,30 +116,18 @@ extension SignalPayload {

/// The operating system and its version
static var systemVersion: String {
#if os(macOS)
return "\(platform) \(ProcessInfo.processInfo.operatingSystemVersion.majorVersion).\(ProcessInfo.processInfo.operatingSystemVersion.minorVersion).\(ProcessInfo.processInfo.operatingSystemVersion.patchVersion)"
#elseif os(iOS)
if #available(iOS 14.0, *), ProcessInfo.processInfo.isiOSAppOnMac {
var size = 0
sysctlbyname("kern.osproductversion", nil, &size, nil, 0)
var machine = [CChar](repeating: 0, count: size)
sysctlbyname("kern.osproductversion", &machine, &size, nil, 0)
return "\(platform) \(String(cString: machine))"
}
return "\(platform) \(UIDevice.current.systemVersion)"
#elseif os(watchOS)
return "\(platform) \(WKInterfaceDevice.current().systemVersion)"
#elseif os(tvOS)
return "\(platform) \(UIDevice.current.systemVersion)"
#else
return "\(platform)"
#endif
return "\(platform) \(ProcessInfo.processInfo.operatingSystemVersion.majorVersion).\(ProcessInfo.processInfo.operatingSystemVersion.minorVersion).\(ProcessInfo.processInfo.operatingSystemVersion.patchVersion)"
}

/// The major system version, i.e. iOS 15
static var majorSystemVersion: String {
return "\(platform) \(ProcessInfo.processInfo.operatingSystemVersion.majorVersion)"
}

/// The major system version, i.e. iOS 15
static var majorMinorSystemVersion: String {
return "\(platform) \(ProcessInfo.processInfo.operatingSystemVersion.majorVersion).\(ProcessInfo.processInfo.operatingSystemVersion.minorVersion)"
}

/// The Bundle Short Version String, as described in Info.plist
static var appVersion: String {
Expand Down Expand Up @@ -218,7 +207,7 @@ extension SignalPayload {
return "macCatalyst"
#else
if #available(iOS 14.0, *), ProcessInfo.processInfo.isiOSAppOnMac {
return "macOS"
return "isiOSAppOnMac"
}
return "iOS"
#endif
Expand Down

0 comments on commit 7b3f436

Please sign in to comment.