O2.swift 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. import CocoaLumberjack
  10. struct O2 {
  11. //考勤打卡版本判断用的 userDefaults的key
  12. public static let O2_Attendance_version_key = "attendance_version_key"
  13. public static let O2_Word_draft_mode = "draft"
  14. public static let O2_First_ID = "(0)"
  15. /// EZSE: Returns app's name
  16. public static var appDisplayName: String? {
  17. if let bundleDisplayName = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String {
  18. return bundleDisplayName
  19. } else if let bundleName = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String {
  20. return bundleName
  21. }
  22. return nil
  23. }
  24. /// EZSE: Returns app's version number
  25. public static var appVersion: String? {
  26. return Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
  27. }
  28. /// EZSE: Return app's build number
  29. public static var appBuild: String? {
  30. return Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as? String
  31. }
  32. /// EZSE: Return app's bundle ID
  33. public static var appBundleID: String? {
  34. return Bundle.main.bundleIdentifier
  35. }
  36. /// EZSE: Returns both app's version and build numbers "v0.3(7)"
  37. public static var appVersionAndBuild: String? {
  38. if appVersion != nil && appBuild != nil {
  39. if appVersion == appBuild {
  40. return "v\(appVersion!)"
  41. } else {
  42. return "v\(appVersion!)(\(appBuild!))"
  43. }
  44. }
  45. return nil
  46. }
  47. /// EZSE: Return device version ""
  48. public static var deviceVersion: String {
  49. var size: Int = 0
  50. sysctlbyname("hw.machine", nil, &size, nil, 0)
  51. var machine = [CChar](repeating: 0, count: Int(size))
  52. sysctlbyname("hw.machine", &machine, &size, nil, 0)
  53. return String(cString: machine)
  54. }
  55. // MARK: - 本地缓存目录
  56. /// 会议管理缓存目录
  57. public static func meetingFileLocalFolder() -> URL {
  58. let manager = FileManager.default
  59. let documentsURL = manager.urls(for: .documentDirectory, in: .userDomainMask)[0]
  60. let meetingFolder = documentsURL
  61. .appendingPathComponent("O2")
  62. .appendingPathComponent("meeting")
  63. if !manager.fileExists(atPath: meetingFolder.path) {
  64. do {
  65. try manager.createDirectory(at: meetingFolder, withIntermediateDirectories: true, attributes: nil)
  66. } catch {
  67. DDLogError("创建文件夹错误,\(error.localizedDescription)")
  68. }
  69. }
  70. return meetingFolder
  71. }
  72. ///云盘缓存目录
  73. public static func cloudFileLocalFolder() -> URL {
  74. let manager = FileManager.default
  75. let documentsURL = manager.urls(for: .documentDirectory, in: .userDomainMask)[0]
  76. let cloudFolder = documentsURL
  77. .appendingPathComponent("O2")
  78. .appendingPathComponent("cloud")
  79. if !manager.fileExists(atPath: cloudFolder.path) {
  80. do {
  81. try manager.createDirectory(at: cloudFolder, withIntermediateDirectories: true, attributes: nil)
  82. } catch {
  83. DDLogError("创建文件夹错误,\(error.localizedDescription)")
  84. }
  85. }
  86. return cloudFolder
  87. }
  88. ///base64缓存目录
  89. public static func base64CacheLocalFolder() -> URL {
  90. let manager = FileManager.default
  91. let documentsURL = manager.urls(for: .documentDirectory, in: .userDomainMask)[0]
  92. let base64Folder = documentsURL
  93. .appendingPathComponent("O2")
  94. .appendingPathComponent("base64")
  95. if !manager.fileExists(atPath: base64Folder.path) {
  96. do {
  97. try manager.createDirectory(at: base64Folder, withIntermediateDirectories: true, attributes: nil)
  98. } catch {
  99. DDLogError("创建文件夹错误,\(error.localizedDescription)")
  100. }
  101. }
  102. return base64Folder
  103. }
  104. ///info缓存目录
  105. public static func inforCacheLocalFolder() -> URL {
  106. let manager = FileManager.default
  107. let documentsURL = manager.urls(for: .documentDirectory, in: .userDomainMask)[0]
  108. let inforFolder = documentsURL
  109. .appendingPathComponent("O2")
  110. .appendingPathComponent("infor")
  111. if !manager.fileExists(atPath: inforFolder.path) {
  112. do {
  113. try manager.createDirectory(at: inforFolder, withIntermediateDirectories: true, attributes: nil)
  114. } catch {
  115. DDLogError("创建文件夹错误,\(error.localizedDescription)")
  116. }
  117. }
  118. return inforFolder
  119. }
  120. ///删除文件夹
  121. public static func deleteFolder(folder: URL) {
  122. do{
  123. try FileManager.default.removeItem(atPath: folder.path)
  124. }catch{
  125. DDLogError("删除目录失败,\(error.localizedDescription)")
  126. }
  127. }
  128. }