我在我的 iOS 应用程序中使用 Swift 中的 present 显示 GADInterstitialAd
。下面是我用来展示广告的代码。
func showAd() {
if self.interstitialAd.isReady {
self.interstitialAd.present(fromRootViewController: self)
}
}
我在屏幕上运行一个计时器,我想在广告从屏幕上消失后暂停和恢复。谁能告诉我如何实现这个?我检查了 interstitialWillDismissScreen
但似乎为此我需要从 GADInterstitialDelegate
派生自定义类。截至目前,我直接使用 var interstitialAd: GADInterstitial!
我想知道是否有任何方法可以检查广告何时打开和关闭屏幕?
最佳答案
您需要在您的类中包含 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")
}
}
关于ios - 如何检测用户何时关闭 Swift iOS 中的插页式广告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43816421/