Reputation: 291
I'm showing GADInterstitialAd
in my iOS app using present in Swift. 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
. As of now I'm directly using var interstitialAd: GADInterstitial!
and I'm wondering if there is any way I can just check when Ad is on and off the screen?
Upvotes: 1
Views: 2468
Reputation: 18898
You need to include GADInterstitialDelegate
in your class. 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")
}
}
Upvotes: 3