gpt4 book ai didi

ios - View 层次结构中的 GADInterstitial 重复项

转载 作者:行者123 更新时间:2023-12-01 19:54:47 24 4
gpt4 key购买 nike

我有一个 GADInterstitial 的实现

class AdsManager {

let adsAppId = MY_ID
let fullScreenAdUnitId = MY_ID

static let manager: AdsManager = AdsManager()

private var interstitial: GADInterstitial!

private init () {
createAndLoadInterstitial()
}

func presentInterstitial(fromViewController viewController: UIViewController) {
if interstitial.isReady {
interstitial.present(fromRootViewController: viewController)
}
else {
print("Interstitial is not ready")
}

createAndLoadInterstitial()
}

private func createAndLoadInterstitial() {
//TODO: replace test ad unit id with production
interstitial = GADInterstitial(adUnitID: MY_ID)
interstitial.load(GADRequest())
}
}

我这样展示这个广告:
func touchedButton(_ sender: UIButton) {
AdsManager.manager.presentInterstitial(fromViewController: self)
}

Everythink 工作并且看起来不错,但是当我调试时,我发现了一些奇怪的东西:

enter image description here

同一 View 的四个实例。有谁知道好用吗?或者,也许我在 AdsManager 中犯了一个错误。 ?也许 Firebase 实现错误?

最佳答案

数量GADUIKitWebView的取决于所呈现的广告类型。视频、图片和文字广告都有不同的布局。根据使用的内存量,我认为它是正确的。

查看交互式 GADInterstitial 的层次结构广告:

enter image description here

除此之外,您的实现确实存在问题。您的问题出在此功能中:

func presentInterstitial(fromViewController viewController: UIViewController) {
if interstitial.isReady {
interstitial.present(fromRootViewController: viewController)
}
else {
print("Interstitial is not ready")
}

createAndLoadInterstitial() // PROBLEM
}

你应该移动 createAndLoadInterstitial()进入 else所以你只加载另一个 GADInterstitial当你真正需要的时候。例如:
func presentInterstitial(fromViewController viewController: UIViewController) {
if interstitial.isReady {
interstitial.present(fromRootViewController: viewController)
}
else {
print("Interstitial is not ready")
createAndLoadInterstitial()
}
}

除此之外,您应该实现 GADInterstitial delegate methods并加载另一个 GADInterstitial只有在它关闭屏幕后。例如:
/// Called just after dismissing an interstitial and it has animated off the screen.
func interstitialDidDismissScreen(_ ad: GADInterstitial) {
print("interstitialDidDismissScreen")
createAndLoadInterstitial()
}

关于ios - View 层次结构中的 GADInterstitial 重复项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43350516/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com