KMAdvertisementConfig.swift 5.5 KB

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