KMAdvertisementConfig.swift 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. //
  2. // KMAdvertisementConfig.swift
  3. // KMAdvertisement
  4. //
  5. // Created by lizhe on 2022/11/24.
  6. //
  7. #if os(OSX)
  8. import AppKit
  9. #elseif os(iOS)
  10. import UIKit
  11. #endif
  12. //APP类型
  13. @objc public enum KMAdvertisementAppNameType: Int, Codable {
  14. case RecordIt = 0
  15. case RecordItPro = 1
  16. case RecordItDMG = 2
  17. case FilmageScreen = 3
  18. case FilmageScreenPro = 4
  19. case FilmageScreenDMG = 5
  20. case FilmageEditorMac = 6
  21. case FilmageEditorMacPro = 7
  22. case FilmageEditorMacDMG = 8
  23. case FilmageConverterMac = 9
  24. case FilmageConverterMacPro = 10
  25. case FilmageConverterMacDMG = 11
  26. case FilmagePlayerMac = 12
  27. case FilmagePlayerMacPro = 13
  28. case FilmagePlayerMacDMG = 14
  29. case PDFReaderProMac = 15
  30. case PDFReaderProMacPro = 16
  31. case PDFReaderProMacDMG = 17
  32. case PDFReaderProIOS = 18
  33. case PDFReaderProIOSPro = 19
  34. func string() -> String {
  35. switch self {
  36. case .RecordIt: return "RecordIt"
  37. case .RecordItPro: return "RecordItPro"
  38. case .RecordItDMG: return "RecordItDMG"
  39. case .FilmageScreen: return "FilmageScreen"
  40. case .FilmageScreenPro: return "FilmageScreenPro"
  41. case .FilmageScreenDMG: return "FilmageScreenDMG"
  42. case .FilmageEditorMac: return "FilmageEditorMac"
  43. case .FilmageEditorMacPro: return "FilmageEditorMacPro"
  44. case .FilmageEditorMacDMG: return "FilmageEditorMacDMG"
  45. case .FilmageConverterMac: return "FilmageConverterMac"
  46. case .FilmageConverterMacPro: return "FilmageConverterMacPro"
  47. case .FilmageConverterMacDMG: return "FilmageConverterMacDMG"
  48. case .FilmagePlayerMac: return "FilmagePlayerMac"
  49. case .FilmagePlayerMacPro: return "FilmagePlayerMacPro"
  50. case .FilmagePlayerMacDMG: return "FilmagePlayerMacDMG"
  51. case .PDFReaderProMac: return "PDFReaderProMac"
  52. case .PDFReaderProMacPro: return "PDFReaderProMacPro"
  53. case .PDFReaderProMacDMG: return "PDFReaderProMacDMG"
  54. case .PDFReaderProIOS: return "PDFReaderProIOS"
  55. case .PDFReaderProIOSPro: return "PDFReaderProIOSPro"
  56. }
  57. }
  58. }
  59. //显示样式
  60. @objc public enum KMAdvertisementShowType: Int, Codable {
  61. case unknow = 0
  62. case list = 1 //列表
  63. case pop = 2 //弹窗
  64. case scroll = 3 //循环
  65. case view = 4 //视图显示
  66. }
  67. //平台
  68. @objc public enum KMAdvertisementPlatformType: Int, Codable {
  69. case unknow = 0
  70. case Mac //
  71. case iOS //
  72. }
  73. //订阅状态
  74. @objc public enum KMAdvertisementSubscribeType: Int, Codable {
  75. case unknow = 0
  76. case unsubscribed = 1 //未订阅
  77. case subscribed = 2 //已订阅
  78. case all = 3 //无限制
  79. }
  80. //点击视图后跳转选项
  81. @objc public enum KMAdvertisementActionType: Int, Codable {
  82. case unknow = 0
  83. case URL = 1 //链接
  84. case comparative = 2 //比价表
  85. }
  86. //多语
  87. @objc public enum KMAdvertisementLanguageType: Int, Codable {
  88. case unknow
  89. case en //
  90. case zhCN //
  91. case zhTW //
  92. }
  93. @objcMembers open class KMAdvertisementConfig: NSObject {
  94. var appName: KMAdvertisementAppNameType = .FilmageEditorMac
  95. var platform: KMAdvertisementPlatformType = .Mac
  96. public var subscribeType: KMAdvertisementSubscribeType = .unsubscribed
  97. public var language: KMAdvertisementLanguageType = .unknow
  98. func activityBaseURL() -> String {
  99. if (KMAdvertisementManager.manager.debug) {
  100. // 测试 服务器
  101. return "http://test-store.kdan.cn:3019"
  102. } else {
  103. //正式版 服务器
  104. return "https://store.filmagepro.com:3018"
  105. }
  106. }
  107. public func initParameters(appName: KMAdvertisementAppNameType, subscribeType:KMAdvertisementSubscribeType, platform: KMAdvertisementPlatformType) {
  108. self.appName = appName
  109. self.subscribeType = subscribeType
  110. self.platform = platform
  111. }
  112. }
  113. extension KMAdvertisementConfig {
  114. static func adapterDark(light: AnyObject, dark: AnyObject) -> AnyObject {
  115. if self.isDarkModel() {
  116. return dark
  117. } else {
  118. return light
  119. }
  120. }
  121. static func isDarkModel() -> Bool {
  122. #if os(iOS)
  123. if #available(iOS 12.0, *) {
  124. if UITraitCollection.current.userInterfaceStyle == UIUserInterfaceStyle.dark {
  125. return true
  126. } else {
  127. return false
  128. }
  129. }
  130. #elseif os(OSX)
  131. if #available(macOS 10.14, *) {
  132. let dict = UserDefaults.standard.persistentDomain(forName: UserDefaults.globalDomain) ?? nil
  133. guard let dicts: Dictionary = dict else {
  134. // print("不是字典类型")
  135. return false
  136. }
  137. guard let style = dicts["AppleInterfaceStyle"] as? String else {
  138. print("style is not string")
  139. return false
  140. }
  141. let isDarkMode : Bool = style.compare("Dark").rawValue == 0
  142. if isDarkMode {
  143. // print("暗黑模式\(style)")
  144. return true
  145. } else {
  146. // print("正常模式\(style)")
  147. return false
  148. }
  149. } else {
  150. return false
  151. }
  152. #endif
  153. }
  154. }