ViewController.swift 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // ViewController.swift
  3. // KMAdvertisementDemo_Mac
  4. //
  5. // Created by lizhe on 2022/11/23.
  6. //
  7. import Cocoa
  8. import KMAdvertisement
  9. class ViewController: NSViewController {
  10. //list
  11. @IBOutlet weak var showListView: NSView!
  12. @IBOutlet weak var tableView: KMAdvertisementTableView!
  13. //view
  14. @IBOutlet weak var showView: NSView!
  15. @IBOutlet weak var advertisementView: KMAdvertisementShowView!
  16. override func viewDidLoad() {
  17. super.viewDidLoad()
  18. self.showListView.wantsLayer = true
  19. self.showListView.layer?.backgroundColor = NSColor.black.withAlphaComponent(0.3).cgColor
  20. // Do any additional setup after loading the view.
  21. //设置基础参数
  22. KMAdvertisementManager.manager.initConfig(appName: .FilmageEditorMac,
  23. subscribeType: .unsubscribed,
  24. platform: .Mac)
  25. //测试模式,默认false
  26. KMAdvertisementManager.manager.debug = true
  27. unowned let weakSelf = self
  28. //获取广告数据
  29. KMAdvertisementManager.manager.fetchData { data, error in
  30. if data != nil {
  31. for model in data! {
  32. if model.showType == .list {
  33. //视图加载方法一
  34. let view = KMAdvertisementManager.manager.show(type: KMAdvertisementShowType.list, data: model, superView: weakSelf.showListView) { actionItem in
  35. print("list 1")
  36. }
  37. //视图加载方法二
  38. weakSelf.tableView.inputData = model
  39. weakSelf.tableView.actionCompletion = { actionItem in
  40. print("list 2")
  41. }
  42. }
  43. if model.showType == .view {
  44. //视图加载方法一
  45. let view = KMAdvertisementManager.manager.show(type: KMAdvertisementShowType.view, data: model, superView: weakSelf.showView) { actionItem in
  46. print("view 1")
  47. }
  48. //视图加载方法二
  49. weakSelf.advertisementView.inputData = model
  50. weakSelf.advertisementView.actionCompletion = { actionItem in
  51. print("view 2")
  52. }
  53. }
  54. }
  55. }
  56. }
  57. }
  58. override var representedObject: Any? {
  59. didSet {
  60. // Update the view, if already loaded.
  61. }
  62. }
  63. }