ViewController.swift 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 in
  32. print("点击了 scroll 1")
  33. }
  34. //视图加载方法二
  35. weakSelf.advertisementScroll.inputData = model
  36. weakSelf.advertisementScroll.actionCompletion = { actionItem in
  37. print("点击了 scroll 2")
  38. }
  39. }
  40. if model.showType == .view {
  41. //视图加载方法一
  42. let view = KMAdvertisementManager.manager.show(type: .view, data: model, superView: weakSelf.showView) { actionItem in
  43. print("点击了 view 1")
  44. }
  45. //视图加载方法二
  46. weakSelf.advertisementView.inputData = model
  47. weakSelf.advertisementView.actionCompletion = { actionItem in
  48. print("点击了 view 2")
  49. }
  50. }
  51. }
  52. }
  53. }
  54. }
  55. }