O2.swift 6.4 KB

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