Skip to content

Instantly share code, notes, and snippets.

@kristofk
Last active August 23, 2018 10:15
Show Gist options
  • Save kristofk/11b0d1cfadd829589a108265be2b9ade to your computer and use it in GitHub Desktop.
Save kristofk/11b0d1cfadd829589a108265be2b9ade to your computer and use it in GitHub Desktop.
Get meta data like iPhone and iOS version of device
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
}
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