diff --git a/Example/ViewController.swift b/Example/ViewController.swift index 3c1ec86..75cbd3d 100644 --- a/Example/ViewController.swift +++ b/Example/ViewController.swift @@ -15,7 +15,7 @@ class ViewController: UIViewController { super.viewDidLoad() /*** Display the device version ***/ - switch Device.version() { + switch Device.versionOnSimulator() { /*** iPhone ***/ case .iPhone4: print("It's an iPhone 4") case .iPhone4S: print("It's an iPhone 4S") diff --git a/Source/iOS/Device.swift b/Source/iOS/Device.swift index ee1cf67..ef31a0b 100644 --- a/Source/iOS/Device.swift +++ b/Source/iOS/Device.swift @@ -93,6 +93,23 @@ open class Device { return getVersion(code: getVersionCode()) } + static public func versionOnSimulator() -> Version { + let version = self.version() + if version == .simulator { + guard let modelIdentifier = ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"] else { + return version + } + let simulatorVersion = getVersion(code: modelIdentifier); + if simulatorVersion != .unknown { + return simulatorVersion + }else{ + return version + } + }else{ + return version + } + } + static public func size() -> Size { let w: Double = Double(UIScreen.main.bounds.width) let h: Double = Double(UIScreen.main.bounds.height)