O2.swift 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // O2.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2019/9/26.
  6. // Copyright © 2019 zoneland. All rights reserved.
  7. //
  8. import Foundation
  9. struct O2 {
  10. /// EZSE: Returns app's name
  11. public static var appDisplayName: String? {
  12. if let bundleDisplayName = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String {
  13. return bundleDisplayName
  14. } else if let bundleName = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String {
  15. return bundleName
  16. }
  17. return nil
  18. }
  19. /// EZSE: Returns app's version number
  20. public static var appVersion: String? {
  21. return Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
  22. }
  23. /// EZSE: Return app's build number
  24. public static var appBuild: String? {
  25. return Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as? String
  26. }
  27. /// EZSE: Return app's bundle ID
  28. public static var appBundleID: String? {
  29. return Bundle.main.bundleIdentifier
  30. }
  31. /// EZSE: Returns both app's version and build numbers "v0.3(7)"
  32. public static var appVersionAndBuild: String? {
  33. if appVersion != nil && appBuild != nil {
  34. if appVersion == appBuild {
  35. return "v\(appVersion!)"
  36. } else {
  37. return "v\(appVersion!)(\(appBuild!))"
  38. }
  39. }
  40. return nil
  41. }
  42. /// EZSE: Return device version ""
  43. public static var deviceVersion: String {
  44. var size: Int = 0
  45. sysctlbyname("hw.machine", nil, &size, nil, 0)
  46. var machine = [CChar](repeating: 0, count: Int(size))
  47. sysctlbyname("hw.machine", &machine, &size, nil, 0)
  48. return String(cString: machine)
  49. }
  50. }