【问题标题】:How to detect when user dismisses an interstitial Ad in Swift iOS?如何检测用户何时关闭 Swift iOS 中的插页式广告?
【发布时间】:2017-05-06 03:27:58
【问题描述】:

我正在使用 Swift 中的 present 在我的 iOS 应用程序中显示 GADInterstitialAd。下面是我用来展示广告的代码。

func showAd() {
    if self.interstitialAd.isReady {
        self.interstitialAd.present(fromRootViewController: self)
    }
}

我正在屏幕上运行一个计时器,我想在广告从屏幕上消失后暂停和恢复。谁能告诉我如何实现这个?我检查了interstitialWillDismissScreen,但似乎我需要从GADInterstitialDelegate 派生我的自定义类。截至目前,我直接使用var interstitialAd: GADInterstitial!,我想知道是否有任何方法可以检查广告何时打开和关闭?

【问题讨论】:

  • 你需要让你的班级代表 GADInterstitialDelegate ,据我所知,别无选择。你有理由不想这样做吗?
  • 我在丹尼尔下面的评论之后意识到了这一点。我想我误解了这个概念,但是在丹尼尔从下面的示例代码之后变得相当容易。感谢您的评论@AmodGokhale

标签: ios swift admob gadinterstitial


【解决方案1】:

您需要在您的课程中加入GADInterstitialDelegate。没有其他方法可以检查广告是否在屏幕上。

class ViewController: UIViewController, GADInterstitialDelegate {

    var interstitial: GADInterstitial!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Setup interstitial here
        // Set its delegate
        interstitial.delegate = self
    }

    func interstitialWillPresentScreen(_ ad: GADInterstitial) {
        print("Ad presented")
    }

    func interstitialDidDismissScreen(_ ad: GADInterstitial) {
        // Send another GADRequest here
        print("Ad dismissed")
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-10
    相关资源
    最近更新 更多