// // ViewController.swift // KMAdvertisementDemo_Mac // // Created by lizhe on 2022/11/23. // import Cocoa import KMAdvertisement class ViewController: NSViewController { //list @IBOutlet weak var showListView: NSView! @IBOutlet weak var tableView: KMAdvertisementTableView! //view @IBOutlet weak var showView: NSView! @IBOutlet weak var advertisementView: KMAdvertisementShowView! override func viewDidLoad() { super.viewDidLoad() self.showListView.wantsLayer = true self.showListView.layer?.backgroundColor = NSColor.black.withAlphaComponent(0.3).cgColor // Do any additional setup after loading the view. //设置基础参数 KMAdvertisementManager.manager.initConfig(appName: .FilmageEditorMac, subscribeType: .unsubscribed, platform: .Mac) //测试模式,默认false KMAdvertisementManager.manager.debug = true unowned let weakSelf = self //获取广告数据 KMAdvertisementManager.manager.fetchData { data, error in if data != nil { for model in data! { if model.showType == .list { //视图加载方法一 let view = KMAdvertisementManager.manager.show(type: KMAdvertisementShowType.list, data: model, superView: weakSelf.showListView) { actionItem in print("list 1") } //视图加载方法二 weakSelf.tableView.inputData = model weakSelf.tableView.actionCompletion = { actionItem in print("list 2") } } if model.showType == .view { //视图加载方法一 let view = KMAdvertisementManager.manager.show(type: KMAdvertisementShowType.view, data: model, superView: weakSelf.showView) { actionItem in print("view 1") } //视图加载方法二 weakSelf.advertisementView.inputData = model weakSelf.advertisementView.actionCompletion = { actionItem in print("view 2") } } } } } } override var representedObject: Any? { didSet { // Update the view, if already loaded. } } }