简体   繁体   English

如何检测用户何时在Swift iOS中删除插页式广告?

[英]How to detect when user dismisses an interstitial Ad in Swift iOS?

I'm showing GADInterstitialAd in my iOS app using present in Swift. 我正在使用Swift中的礼物在我的iOS应用程序中显示GADInterstitialAd Below is the code I'm using to show ad. 以下是我用来展示广告的代码。

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

I'm running a timer on screen which I want to pause and resume once the ad is dismissed off the screen. 我正在屏幕上运行一个计时器,我希望暂停并在广告从屏幕上解除后恢复。 Can anybody tell me how to implement this? 谁能告诉我如何实现这个? I checked interstitialWillDismissScreen but seems like for that I need to have my custom class derived from GADInterstitialDelegate . 我检查了interstitialWillDismissScreen但似乎我需要从GADInterstitialDelegate派生我的自定义类。 As of now I'm directly using var interstitialAd: GADInterstitial! 截至目前,我正在使用var interstitialAd: GADInterstitial! and I'm wondering if there is any way I can just check when Ad is on and off the screen? 而且我想知道是否有任何方法可以检查广告何时开启和关闭?

You need to include GADInterstitialDelegate in your class. 您需要在班级中包含GADInterstitialDelegate There is no other way to check if the ad is on screen. 没有其他方法可以检查广告是否在屏幕上。

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")
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM