O2.swift 1.9 KB

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