Last active
August 23, 2018 10:15
-
-
Save kristofk/11b0d1cfadd829589a108265be2b9ade to your computer and use it in GitHub Desktop.
Get meta data like iPhone and iOS version of device
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct DeviceMeta { | |
/// Version of the application. | |
static let appVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String | |
/// Name of the current operation system. (ios/macos/...) | |
static let osType = UIDevice.current.systemName | |
/// Version of the operating system. (e.g. 11.4) | |
static let osVersion = UIDevice.current.systemVersion | |
/// Identifier of the device. (e.g. iPhone8,2) | |
static let deviceType = UIDevice.modelIdentifier | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIDevice { | |
static var modelIdentifier: String = { | |
var systemInfo = utsname() | |
uname(&systemInfo) | |
let machineMirror = Mirror(reflecting: systemInfo.machine) | |
let identifier = machineMirror.children.reduce("") { identifier, element in | |
guard let value = element.value as? Int8, value != 0 else { return identifier } | |
return identifier + String(UnicodeScalar(UInt8(value))) | |
} | |
return identifier | |
}() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment