union_ad_ssgf/ios/Classes/Page/FAQSplashPage.swift
2024-10-23 17:03:18 +08:00

137 lines
4.2 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// 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 {
return
}
// 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)")
}
}