50 lines
1.5 KiB
Swift
50 lines
1.5 KiB
Swift
import Foundation
|
|
|
|
#if canImport(UIKit)
|
|
import UIKit
|
|
#endif
|
|
#if os(watchOS)
|
|
import WatchKit
|
|
#endif
|
|
|
|
/// Device information for migration context.
|
|
public struct DeviceInfo: Sendable {
|
|
/// Current platform (iOS, watchOS, unknown).
|
|
public let platform: Platform
|
|
/// OS version string.
|
|
public let systemVersion: String
|
|
/// Device model identifier or marketing name.
|
|
public let model: String
|
|
/// Whether the device is a simulator.
|
|
public let isSimulator: Bool
|
|
|
|
/// Current device info derived from the running environment.
|
|
public static let current = DeviceInfo()
|
|
|
|
private init() {
|
|
#if os(iOS)
|
|
self.platform = .iOS
|
|
self.systemVersion = UIDevice.current.systemVersion
|
|
self.model = UIDevice.current.model
|
|
#elseif os(watchOS)
|
|
self.platform = .watchOS
|
|
self.systemVersion = WKInterfaceDevice.current().systemVersion
|
|
self.model = WKInterfaceDevice.current().model
|
|
#else
|
|
self.platform = .unknown
|
|
self.systemVersion = ProcessInfo.processInfo.operatingSystemVersionString
|
|
self.model = "Unknown"
|
|
#endif
|
|
|
|
self.isSimulator = ProcessInfo.processInfo.environment["SIMULATOR_DEVICE_NAME"] != nil
|
|
}
|
|
|
|
/// Creates a custom device info instance (useful for tests).
|
|
public init(platform: Platform, systemVersion: String, model: String, isSimulator: Bool) {
|
|
self.platform = platform
|
|
self.systemVersion = systemVersion
|
|
self.model = model
|
|
self.isSimulator = isSimulator
|
|
}
|
|
}
|