初步添加 ios 广告逻辑

This commit is contained in:
Jin857
2024-10-23 17:03:18 +08:00
parent 578c1974c5
commit 2345b719dd
29 changed files with 946 additions and 67 deletions

View File

@@ -0,0 +1,136 @@
//
// 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)")
}
}