ViewController.swift 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // ViewController.swift
  3. // KMAdvertisementDemo_iOS
  4. //
  5. // Created by lizhe on 2022/11/23.
  6. //
  7. import UIKit
  8. import KMAdvertisement_iOS
  9. class ViewController: UIViewController {
  10. @IBOutlet weak var advertisementView: KMAdvertisementShowView_iOS!
  11. @IBOutlet weak var showView: UIView!
  12. @IBOutlet weak var advertisementScroll: KMAdvertisementShowScroll_iOS!
  13. @IBOutlet weak var showScrollView: UIView!
  14. override func viewDidLoad() {
  15. super.viewDidLoad()
  16. // Do any additional setup after loading the view.
  17. // Do any additional setup after loading the view.
  18. //设置基础参数
  19. KMAdvertisementManager.manager.initConfig(appName: .PDFReaderProIOS,
  20. subscribeType: .unsubscribed,
  21. platform: .iOS)
  22. //测试模式,默认false
  23. KMAdvertisementManager.manager.debug = true
  24. unowned let weakSelf = self
  25. //获取广告数据
  26. KMAdvertisementManager.manager.fetchData { data, error in
  27. if data != nil {
  28. for model in data! {
  29. if model.showType == .scroll {
  30. //视图加载方法一
  31. let view = KMAdvertisementManager.manager.show(type: .scroll, data: model, superView: weakSelf.showScrollView) { actionType, actionItem in
  32. print("点击了 scroll 1")
  33. } _: { data in
  34. print("数据刷新了")
  35. }
  36. // //视图加载方法二
  37. // weakSelf.advertisementScroll.inputData = model
  38. // weakSelf.advertisementScroll.actionCompletion = { actionType, actionItem in
  39. // print("点击了 scroll 2")
  40. // }
  41. }
  42. if model.showType == .view {
  43. //视图加载方法一
  44. let view = KMAdvertisementManager.manager.show(type: .view, data: model, superView: weakSelf.showView) { actionType, actionItem in
  45. print("点击了 view 1")
  46. } _: { data in
  47. print("数据刷新了")
  48. }
  49. //视图加载方法二
  50. weakSelf.advertisementView.inputData = model
  51. weakSelf.advertisementView.actionCompletion = { actionType, actionItem in
  52. print("点击了 view 2")
  53. }
  54. }
  55. }
  56. }
  57. }
  58. }
  59. }