// // FAQSplashPage.swift // Pods // // Created by Jin on 10/23/24. // import UIKit import Flutter class FAQSplashPage: FAQBaseAdPage, GDTSplashAdDelegate { var splashAd: GDTSplashAd! var fullScreenAd: Bool = false var bottomView: UIView? // 加载广告 override func loadAd(call: FlutterMethodCall) { // 获取 logo 和 fetchDelay guard let arguments = call.arguments as? [String: Any], let logo = arguments["logo"] as? String, let fetchDelay = arguments["fetchDelay"] as? CGFloat else { } print("---->>> logo: \(logo)") // logo 判断为空,则全屏展示 self.fullScreenAd = logo.isEmpty // 初始化开屏广告 self.splashAd = GDTSplashAd(placementId: self.posId) // 确保 FAQSplashPage 遵循适当的协议 self.splashAd.delegate = self // 设置超时时长 self.splashAd.fetchDelay = fetchDelay // 加载全屏广告 if self.fullScreenAd { self.splashAd.loadFullScreenAd() } else { // 加载半屏广告 self.splashAd.load() // 设置底部 logo self.bottomView = nil let size = UIScreen.main.bounds.size let width = size.width // 这里按照 15% 进行 logo 的展示 let height: CGFloat = 112.5 self.bottomView = UIView(frame: CGRect(x: 0, y: 0, width: width, height: height)) self.bottomView?.backgroundColor = .white if let logoImage = UIImage(named: logo) { let logoView = UIImageView(image: logoImage) logoView.frame = CGRect(x: 0, y: 0, width: width, height: height) logoView.contentMode = .center logoView.center = self.bottomView!.center self.bottomView?.addSubview(logoView) } } } // MARK: - GDTSplashAdDelegate func splashAdDidLoad(_ splashAd: GDTSplashAd) { print("splashAdDidLoad") if let mainWindow = UIApplication.shared.keyWindow { // 加载全屏广告 if self.fullScreenAd { self.splashAd.showFullScreenAd(in: mainWindow, withLogoImage: nil, skip: nil) } else { // 加载半屏广告 self.splashAd.show(in: mainWindow, withBottomView: self.bottomView, skip: nil) } // 发送广告事件 sendEventAction("onAdLoaded") } } func splashAdSuccessPresentScreen(_ splashAd: GDTSplashAd) { print(#function) // 发送广告事件 sendEventAction("onAdPresent") } func splashAdFail(toPresent splashAd: GDTSplashAd, withError error: Error) { print("\( #function) \(error.localizedDescription)") // 发送广告错误事件 sendErrorEvent(error._code, withErrMsg: error.localizedDescription) } func splashAdExposured(_ splashAd: GDTSplashAd) { print(#function) // 发送广告事件 sendEventAction("onAdExposure") } func splashAdClicked(_ splashAd: GDTSplashAd) { print(#function) // 发送广告事件 sendEventAction("onAdClicked") } func splashAdApplicationWillEnterBackground(_ splashAd: GDTSplashAd) { print(#function) } func splashAdWillClosed(_ splashAd: GDTSplashAd) { print(#function) } func splashAdClosed(_ splashAd: GDTSplashAd) { print(#function) self.splashAd = nil // 发送广告事件 sendEventAction("onAdClosed") } func splashAdWillPresentFullScreenModal(_ splashAd: GDTSplashAd) { print(#function) } func splashAdDidPresentFullScreenModal(_ splashAd: GDTSplashAd) { print(#function) } func splashAdWillDismissFullScreenModal(_ splashAd: GDTSplashAd) { print(#function) } func splashAdDidDismissFullScreenModal(_ splashAd: GDTSplashAd) { print(#function) } // 发送错误事件的示例方法 private func sendErrorEvent(_ code: Int, withErrMsg msg: String) { // 实现发送错误事件的逻辑 print("Error sent: \(code); message: \(msg)") } }