Guest User

Untitled

a guest
Dec 11th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. static func deviceName() -> String {
  2. var systemInfo = utsname()
  3. uname(&systemInfo)
  4.  
  5. guard let iOSDeviceModelsPath = Bundle.main.path(forResource: "iOSDeviceModelMapping", ofType: "plist") else {
  6. return ""
  7. }
  8. guard let iOSDevices = NSDictionary(contentsOfFile: iOSDeviceModelsPath) else {
  9. return ""
  10. }
  11.  
  12. let machineMirror = Mirror(reflecting: systemInfo.machine)
  13. let identifier = machineMirror.children.reduce("") { identifier, element in
  14. guard let value = element.value as? Int8, value != 0 else { return identifier }
  15. return identifier + String(UnicodeScalar(UInt8(value)))
  16. }
  17.  
  18. return iOSDevices.value(forKey: identifier) as? String ?? ""
  19. }
Add Comment
Please, Sign In to add comment