1

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

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

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

4

1 回答 1

3

你需要包括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")
    }
}
于 2017-05-06T15:58:27.543 回答