O2.swift 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. public static let O2_First_ID = "(0)"
  11. /// EZSE: Returns app's name
  12. public static var appDisplayName: String? {
  13. if let bundleDisplayName = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String {
  14. return bundleDisplayName
  15. } else if let bundleName = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String {
  16. return bundleName
  17. }
  18. return nil
  19. }
  20. /// EZSE: Returns app's version number
  21. public static var appVersion: String? {
  22. return Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
  23. }
  24. /// EZSE: Return app's build number
  25. public static var appBuild: String? {
  26. return Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as? String
  27. }
  28. /// EZSE: Return app's bundle ID
  29. public static var appBundleID: String? {
  30. return Bundle.main.bundleIdentifier
  31. }
  32. /// EZSE: Returns both app's version and build numbers "v0.3(7)"
  33. public static var appVersionAndBuild: String? {
  34. if appVersion != nil && appBuild != nil {
  35. if appVersion == appBuild {
  36. return "v\(appVersion!)"
  37. } else {
  38. return "v\(appVersion!)(\(appBuild!))"
  39. }
  40. }
  41. return nil
  42. }
  43. /// EZSE: Return device version ""
  44. public static var deviceVersion: String {
  45. var size: Int = 0
  46. sysctlbyname("hw.machine", nil, &size, nil, 0)
  47. var machine = [CChar](repeating: 0, count: Int(size))
  48. sysctlbyname("hw.machine", &machine, &size, nil, 0)
  49. return String(cString: machine)
  50. }
  51. }