user7124426 user7124426 - 1 month ago 21
iOS Question

admob interstitial ad is never ready

i have this game and i created 3 funcions in my gameviewcontroller and here they are

func getInterstitialAd(){
interstitial = GADInterstitial(adUnitID: "ca-app-pub-1782852253088296/5018877964")
let requestInterstitial = GADRequest()
interstitial.load(requestInterstitial)
}



func showAd() {

if (interstitial.isReady == true){
interstitial.present(fromRootViewController: GameViewController())
}else{
print("ad wasn't ready")
interstitial = createAd()
}



}

func createAd() -> GADInterstitial{
let interstital = GADInterstitial(adUnitID: "ca-app-pub-1782852253088296/5018877964")
interstitial.load(GADRequest())
return interstital
}


and in one of my scene called StartMenu , i call those function

var viewController: GameViewController!


and then i call the functions

viewController.getInterstitialAd()
viewController.showAd()


but it always returns ad not ready , and false for interstitial.isReady,
but also the getInterstitial function is always called .

can someone help with that please

Answer

The problem is that it takes time to fetch interstitial ads. Your showAd() is called before ad has been cached. When you implement the GADInterstitialDelegate delegate, there is a function interstitialDidReceiveAd(ad: GADInterstitial!). That is the function that is triggered when ad is ready. That is when interstitial.isReady will return true. Hope this helps :-)