KMAdvertisementConfig.swift 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. @objc public enum KMAdvertisementSubscribeType: Int, Codable {
  81. case unknow = 0
  82. case all //免费版跟付费版都需要显示
  83. case pro //只有付费用户显示
  84. case lite //只有免费用户显示
  85. }
  86. //点击视图后跳转选项
  87. @objc public enum KMAdvertisementActionType: Int, Codable {
  88. case unknow = 0
  89. case URL = 1 //链接
  90. case comparative = 2 //比价表
  91. }
  92. //多语
  93. @objc public enum KMAdvertisementLanguageType: Int, Codable {
  94. case unknow
  95. case en //
  96. case zhCN //
  97. case zhTW //
  98. }
  99. @objcMembers open class KMAdvertisementConfig: NSObject {
  100. var isDebug: Bool = false
  101. var appName: KMAdvertisementAppNameType = .PDFReaderProMacPro
  102. var platform: KMAdvertisementPlatformType = .Mac
  103. public var subscribeType: KMAdvertisementSubscribeType = .unknow
  104. public var language: KMAdvertisementLanguageType = .unknow
  105. func activityBaseURL() -> String {
  106. if kTestMode == 1 {
  107. return "http://test-store.kdan.cn:3019"
  108. } else {
  109. return "https://store.filmagepro.com:3018"
  110. }
  111. }
  112. public func initParameters(appName: KMAdvertisementAppNameType, subscribeType:KMAdvertisementSubscribeType, platform: KMAdvertisementPlatformType) {
  113. self.appName = appName
  114. self.subscribeType = subscribeType
  115. self.platform = platform
  116. }
  117. }
  118. extension KMAdvertisementConfig {
  119. static func adapterDark(light: AnyObject, dark: AnyObject) -> AnyObject {
  120. if self.isDarkModel() {
  121. return dark
  122. } else {
  123. return light
  124. }
  125. }
  126. static func isDarkModel() -> Bool {
  127. #if os(iOS)
  128. if #available(iOS 12.0, *) {
  129. if UITraitCollection.current.userInterfaceStyle == UIUserInterfaceStyle.dark {
  130. return true
  131. } else {
  132. return false
  133. }
  134. }
  135. #elseif os(OSX)
  136. if #available(macOS 10.14, *) {
  137. let dict = UserDefaults.standard.persistentDomain(forName: UserDefaults.globalDomain) ?? nil
  138. guard let dicts: Dictionary = dict else {
  139. // print("不是字典类型")
  140. return false
  141. }
  142. guard let style = dicts["AppleInterfaceStyle"] as? String else {
  143. // print("style is not string")
  144. return false
  145. }
  146. let isDarkMode : Bool = style.compare("Dark").rawValue == 0
  147. if isDarkMode {
  148. // print("暗黑模式\(style)")
  149. return true
  150. } else {
  151. // print("正常模式\(style)")
  152. return false
  153. }
  154. } else {
  155. return false
  156. }
  157. #endif
  158. }
  159. }