// // KMAdvertisementConfig.swift // KMAdvertisement // // Created by lizhe on 2022/11/24. // #if os(OSX) import AppKit #elseif os(iOS) import UIKit #endif //APP类型 @objc public enum KMAdvertisementAppNameType: Int, Codable { case RecordIt = 0 case RecordItPro = 1 case RecordItDMG = 2 case FilmageScreen = 3 case FilmageScreenPro = 4 case FilmageScreenDMG = 5 case FilmageEditorMac = 6 case FilmageEditorMacPro = 7 case FilmageEditorMacDMG = 8 case FilmageConverterMac = 9 case FilmageConverterMacPro = 10 case FilmageConverterMacDMG = 11 case FilmagePlayerMac = 12 case FilmagePlayerMacPro = 13 case FilmagePlayerMacDMG = 14 case PDFReaderProMac = 15 case PDFReaderProMacPro = 16 case PDFReaderProMacDMG = 17 case PDFReaderProIOS = 18 case PDFReaderProIOSPro = 19 func string() -> String { switch self { case .RecordIt: return "RecordIt" case .RecordItPro: return "RecordItPro" case .RecordItDMG: return "RecordItDMG" case .FilmageScreen: return "FilmageScreen" case .FilmageScreenPro: return "FilmageScreenPro" case .FilmageScreenDMG: return "FilmageScreenDMG" case .FilmageEditorMac: return "FilmageEditorMac" case .FilmageEditorMacPro: return "FilmageEditorMacPro" case .FilmageEditorMacDMG: return "FilmageEditorMacDMG" case .FilmageConverterMac: return "FilmageConverterMac" case .FilmageConverterMacPro: return "FilmageConverterMacPro" case .FilmageConverterMacDMG: return "FilmageConverterMacDMG" case .FilmagePlayerMac: return "FilmagePlayerMac" case .FilmagePlayerMacPro: return "FilmagePlayerMacPro" case .FilmagePlayerMacDMG: return "FilmagePlayerMacDMG" case .PDFReaderProMac: return "PDFReaderProMac" case .PDFReaderProMacPro: return "PDFReaderProMacPro" case .PDFReaderProMacDMG: return "PDFReaderProMacDMG" case .PDFReaderProIOS: return "PDFReaderProIOS" case .PDFReaderProIOSPro: return "PDFReaderProIOSPro" } } } //显示样式 @objc public enum KMAdvertisementShowType: Int, Codable { case unknow = 0 case list = 1 //列表 case pop = 2 //弹窗 case scroll = 3 //循环 case view = 4 //视图显示 } //平台 @objc public enum KMAdvertisementPlatformType: Int, Codable { case unknow = 0 case Mac // case iOS // } //订阅状态 @objc public enum KMAdvertisementSubscribeType: Int, Codable { case unknow = 0 case unsubscribed = 1 //未订阅 case subscribed = 2 //已订阅 case all = 3 //无限制 } //点击视图后跳转选项 @objc public enum KMAdvertisementActionType: Int, Codable { case unknow = 0 case URL = 1 //链接 case comparative = 2 //比价表 } //多语 @objc public enum KMAdvertisementLanguageType: Int, Codable { case unknow case en // case zhCN // case zhTW // } @objcMembers open class KMAdvertisementConfig: NSObject { var appName: KMAdvertisementAppNameType = .FilmageEditorMac var platform: KMAdvertisementPlatformType = .Mac public var subscribeType: KMAdvertisementSubscribeType = .unsubscribed public var language: KMAdvertisementLanguageType = .unknow func activityBaseURL() -> String { if (KMAdvertisementManager.manager.debug) { // 测试 服务器 return "http://test-store.kdan.cn:3019" } else { //正式版 服务器 return "https://store.filmagepro.com:3018" } } public func initParameters(appName: KMAdvertisementAppNameType, subscribeType:KMAdvertisementSubscribeType, platform: KMAdvertisementPlatformType) { self.appName = appName self.subscribeType = subscribeType self.platform = platform } } extension KMAdvertisementConfig { static func adapterDark(light: AnyObject, dark: AnyObject) -> AnyObject { if self.isDarkModel() { return dark } else { return light } } static func isDarkModel() -> Bool { #if os(iOS) if #available(iOS 12.0, *) { if UITraitCollection.current.userInterfaceStyle == UIUserInterfaceStyle.dark { return true } else { return false } } #elseif os(OSX) if #available(macOS 10.14, *) { let dict = UserDefaults.standard.persistentDomain(forName: UserDefaults.globalDomain) ?? nil guard let dicts: Dictionary = dict else { // print("不是字典类型") return false } guard let style = dicts["AppleInterfaceStyle"] as? String else { print("style is not string") return false } let isDarkMode : Bool = style.compare("Dark").rawValue == 0 if isDarkMode { // print("暗黑模式\(style)") return true } else { // print("正常模式\(style)") return false } } else { return false } #endif } }