Reputation: 477
I'm making an app with AdMob and the thing is: the app successfully loads the ad, but when trying to present it, it seems like the ad hasn't loaded yet. I've followed the guide on Google AdMob...
Here's what's in my viewDidLoad()
interstitial = GADInterstitial(adUnitID: "ca-app-pub-45863574112xxxxxxxxxx/xxxxxxx")
let request = GADRequest()
interstitial.load(request)
And that's where I'm calling it when clicking on a button:
if self.interstitial.isReady {
self.interstitial.present(fromRootViewController: self)
} else {
let alert = UIAlertController(title: "Couldn't load ad", message: "There was a problem while loading the ad... Still, thank you for wanting to support me :)", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Ok...", style: .cancel, handler: nil))
self.present(alert, animated: true)
}
Well, I get the alert... Can you tell me why?
Upvotes: 1
Views: 869
Reputation: 2603
You can tell yourself why :) by implementing the delegate methods https://developers.google.com/admob/ios/api/reference/Protocols/GADInterstitialDelegate
specifically optional func interstitial(_ ad: GADInterstitial!, didFailToReceiveAdWithError error: Any!)
Upvotes: 3