KMAdvertisementConfig.swift 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 DEBUG
  107. if kTestMode == 1{
  108. return "http://test-store.kdan.cn:3019"
  109. } else {
  110. return "https://store.filmagepro.com:3018"
  111. }
  112. #else
  113. return "https://store.filmagepro.com:3018"
  114. #endif
  115. }
  116. public func initParameters(appName: KMAdvertisementAppNameType, subscribeType:KMAdvertisementSubscribeType, platform: KMAdvertisementPlatformType) {
  117. self.appName = appName
  118. self.subscribeType = subscribeType
  119. self.platform = platform
  120. }
  121. }
  122. extension KMAdvertisementConfig {
  123. static func adapterDark(light: AnyObject, dark: AnyObject) -> AnyObject {
  124. if self.isDarkModel() {
  125. return dark
  126. } else {
  127. return light
  128. }
  129. }
  130. static func isDarkModel() -> Bool {
  131. #if os(iOS)
  132. if #available(iOS 12.0, *) {
  133. if UITraitCollection.current.userInterfaceStyle == UIUserInterfaceStyle.dark {
  134. return true
  135. } else {
  136. return false
  137. }
  138. }
  139. #elseif os(OSX)
  140. if #available(macOS 10.14, *) {
  141. let dict = UserDefaults.standard.persistentDomain(forName: UserDefaults.globalDomain) ?? nil
  142. guard let dicts: Dictionary = dict else {
  143. // print("不是字典类型")
  144. return false
  145. }
  146. guard let style = dicts["AppleInterfaceStyle"] as? String else {
  147. // print("style is not string")
  148. return false
  149. }
  150. let isDarkMode : Bool = style.compare("Dark").rawValue == 0
  151. if isDarkMode {
  152. // print("暗黑模式\(style)")
  153. return true
  154. } else {
  155. // print("正常模式\(style)")
  156. return false
  157. }
  158. } else {
  159. return false
  160. }
  161. #endif
  162. }
  163. }