O2.swift 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. // 云盘版本判断使用
  14. public static let O2CloudFileVersionKey = "cloud_file_version_key"
  15. public static let O2_Word_draft_mode = "draft"
  16. public static let O2_First_ID = "(0)"
  17. // 通讯录权限查询视图key
  18. public static let CUSTOM_STYLE_CONTACT_PERMISSION_PREF_KEY = "customStyleContactPermissionViewKey"
  19. public static let CUSTOM_STYLE_CONTACT_PERMISSION_DEFAULT = "addressPowerView"
  20. public static let defaultPageSize = 15
  21. /// EZSE: Returns app's name
  22. public static var appDisplayName: String? {
  23. if let bundleDisplayName = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String {
  24. return bundleDisplayName
  25. } else if let bundleName = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String {
  26. return bundleName
  27. }
  28. return nil
  29. }
  30. /// EZSE: Returns app's version number
  31. public static var appVersion: String? {
  32. return Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
  33. }
  34. /// EZSE: Return app's build number
  35. public static var appBuild: String? {
  36. return Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as? String
  37. }
  38. /// EZSE: Return app's bundle ID
  39. public static var appBundleID: String? {
  40. return Bundle.main.bundleIdentifier
  41. }
  42. /// EZSE: Returns both app's version and build numbers "v0.3(7)"
  43. public static var appVersionAndBuild: String? {
  44. if appVersion != nil && appBuild != nil {
  45. if appVersion == appBuild {
  46. return "v\(appVersion!)"
  47. } else {
  48. return "v\(appVersion!)(\(appBuild!))"
  49. }
  50. }
  51. return nil
  52. }
  53. /// EZSE: Return device version ""
  54. public static var deviceVersion: String {
  55. var size: Int = 0
  56. sysctlbyname("hw.machine", nil, &size, nil, 0)
  57. var machine = [CChar](repeating: 0, count: Int(size))
  58. sysctlbyname("hw.machine", &machine, &size, nil, 0)
  59. return String(cString: machine)
  60. }
  61. // MARK: - 本地缓存目录
  62. /// 会议管理缓存目录
  63. public static func meetingFileLocalFolder() -> URL {
  64. let manager = FileManager.default
  65. let documentsURL = manager.urls(for: .documentDirectory, in: .userDomainMask)[0]
  66. let meetingFolder = documentsURL
  67. .appendingPathComponent("O2")
  68. .appendingPathComponent("meeting")
  69. if !manager.fileExists(atPath: meetingFolder.path) {
  70. do {
  71. try manager.createDirectory(at: meetingFolder, withIntermediateDirectories: true, attributes: nil)
  72. } catch {
  73. DDLogError("创建文件夹错误,\(error.localizedDescription)")
  74. }
  75. }
  76. return meetingFolder
  77. }
  78. ///云盘缓存目录
  79. public static func cloudFileLocalFolder() -> URL {
  80. let manager = FileManager.default
  81. let documentsURL = manager.urls(for: .documentDirectory, in: .userDomainMask)[0]
  82. let cloudFolder = documentsURL
  83. .appendingPathComponent("O2")
  84. .appendingPathComponent("cloud")
  85. if !manager.fileExists(atPath: cloudFolder.path) {
  86. do {
  87. try manager.createDirectory(at: cloudFolder, withIntermediateDirectories: true, attributes: nil)
  88. } catch {
  89. DDLogError("创建文件夹错误,\(error.localizedDescription)")
  90. }
  91. }
  92. return cloudFolder
  93. }
  94. ///base64缓存目录
  95. public static func base64CacheLocalFolder() -> URL {
  96. let manager = FileManager.default
  97. let documentsURL = manager.urls(for: .documentDirectory, in: .userDomainMask)[0]
  98. let base64Folder = documentsURL
  99. .appendingPathComponent("O2")
  100. .appendingPathComponent("base64")
  101. if !manager.fileExists(atPath: base64Folder.path) {
  102. do {
  103. try manager.createDirectory(at: base64Folder, withIntermediateDirectories: true, attributes: nil)
  104. } catch {
  105. DDLogError("创建文件夹错误,\(error.localizedDescription)")
  106. }
  107. }
  108. return base64Folder
  109. }
  110. ///info缓存目录
  111. public static func inforCacheLocalFolder() -> URL {
  112. let manager = FileManager.default
  113. let documentsURL = manager.urls(for: .documentDirectory, in: .userDomainMask)[0]
  114. let inforFolder = documentsURL
  115. .appendingPathComponent("O2")
  116. .appendingPathComponent("infor")
  117. if !manager.fileExists(atPath: inforFolder.path) {
  118. do {
  119. try manager.createDirectory(at: inforFolder, withIntermediateDirectories: true, attributes: nil)
  120. } catch {
  121. DDLogError("创建文件夹错误,\(error.localizedDescription)")
  122. }
  123. }
  124. return inforFolder
  125. }
  126. ///删除文件夹
  127. public static func deleteFolder(folder: URL) {
  128. do{
  129. try FileManager.default.removeItem(atPath: folder.path)
  130. }catch{
  131. DDLogError("删除目录失败,\(error.localizedDescription)")
  132. }
  133. }
  134. /// 文件后缀 对应的图片
  135. public static func fileExtension2Icon(_ ext: String?) -> String {
  136. guard let et = ext else {
  137. return "icon_file_more"
  138. }
  139. switch et {
  140. case "jpg", "png", "jepg", "gif":
  141. return "icon_img"
  142. case "html":
  143. return "icon_html"
  144. case "xls", "xlsx":
  145. return "icon_excel"
  146. case "doc", "docx":
  147. return "icon_word"
  148. case "ppt", "pptx":
  149. return "icon_ppt"
  150. case "pdf":
  151. return "icon_pdf"
  152. case "mp4":
  153. return "icon_mp4"
  154. case "mp3":
  155. return "icon_mp3"
  156. case "zip", "rar", "7z":
  157. return "icon_zip"
  158. case "txt":
  159. return "file_txt_icon"
  160. default :
  161. return "icon_file_more"
  162. }
  163. }
  164. /// 是否图片文件
  165. public static func isImageExt(_ ext: String?) -> Bool {
  166. guard let e = ext else {
  167. return false
  168. }
  169. switch e.lowercased() {
  170. case "jpg", "png", "jepg", "gif", "bmp":
  171. return true
  172. default:
  173. return false
  174. }
  175. }
  176. }