I am following this tutorial
So far I have got it to work when I click the button. However I cannot seem to get it to show an interstitial ad on viewDidLoad.
This is what I have:
override func viewDidLoad() {
super.viewDidLoad()
self.interstitialAd = GADInterstitial(adUnitID: "ADUnitID")
let request = GADRequest()
// Requests test ads on test devices.
request.testDevices = ["2077ef9a63d2b398840261c8221a0c9b"]
self.interstitialAd.loadRequest(request)
self.interstitialAd = reloadInterstitialAd()
}
The console keeps showing me this:
2016-02-04 22:27:51.855 GoogleAdMobTutorial[3394:56415] To get test ads on this device, call: request.testDevices = @[ kGADSimulatorID ];
When I click the button:
@IBAction func showAd(sender: AnyObject) {
if self.interstitialAd.isReady {
self.interstitialAd.presentFromRootViewController(self)
}
}
The ad shows up. When I dismiss the ad, I get this in the console:
2016-02-04 22:29:16.661 GoogleAdMobTutorial[3394:56743] Request Error: Will not send request because interstitial object has been used.
This is the function that is called when I dismiss the ad:
func interstitialDidDismissScreen(ad: GADInterstitial!) {
self.interstitialAd = reloadInterstitialAd()
}
Question
Just for clarity: How do I get an interstitial ad to show when the viewcontroller loads?