gpt4 book ai didi

ios - 如何在点击后退按钮时显示一次 AdMob Interstitial

转载 作者:行者123 更新时间:2023-11-28 06:36:36 26 4
gpt4 key购买 nike

我有这个代码:

func createAndLoadInterstitial()  {
interstitial = GADInterstitial(adUnitID: "ca-app-pub-xxxxxxxxxx/xxxxx")
interstitial.delegate = self
let request = GADRequest()
interstitial.loadRequest(request)
}

override func viewDidAppear(animated: Bool) {
if (interstitial.isReady && showAd) {
showAd = false
// print("iterstitialMain is ready")
interstitial.presentFromRootViewController(self)
self.createAndLoadInterstitial()
}
else {
showAd = true
}
}

并且有效。但每次用户点击后退按钮时它都会显示一个广告。

我只想在用户点击后退按钮时显示一次广告。过一段时间再展示广告会更好吗?例如,每 5 分钟一次?

最佳答案

最初在哪里将 showAd 设置为 trueif 语句中的逻辑是主要问题。

if 语句中设置 showAd = false 后,下一次 viewDidAppear 将调用您的 else将执行语句,将 showAd 设置回 true

您应该做的是检查您的Bool,然后检查interstitial.isReady。然后,在您的 GADInterstitialinterstitialDidDismissScreen 委托(delegate)方法中,您将更新您的 showAd Bool 并请求另一个 GADInterstitial 如果您愿意。您说您只想显示一个 GADInterstitial,因此没有必要请求另一个。例如:

override func viewDidAppear(animated: Bool) {
if showAd { // Should we show an ad?
if interstitial.isReady { // Is the ad ready?
interstitial.presentFromRootViewController(self)
}
}
else {
// Do nothing
}
}

func interstitialDidDismissScreen(ad: GADInterstitial!) {
// Ad was presented and dismissed
print("interstitialDidDismissScreen")
showAd = false // Don't show anymore ads
}

此外,您还可以更改:

let request = GADRequest()
interstitial.loadRequest(request)

只是:

interstitial.loadRequest(GADRequest())

在您的 createAndLoadInterstitial 函数中。

要回答问题的第二部分,询问您是否应该在延迟一段时间后展示广告,这违反了 AdMob 计划政策。

不合规实现的示例:

  • Interstitial ads that appear before the app has opened or after the app has closed.
  • Interstitial ads that are triggered after a user closes another interstitial ad.
  • Interstitial ads loading unexpectedly while a user is viewing the app’s content. Remember to only serve interstitials between pages of content.
  • Interstitial ads that trigger after every user click.
  • Interstitial ads that appear during periods of game play or heavy user interaction.

关于ios - 如何在点击后退按钮时显示一次 AdMob Interstitial,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38931985/

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