So I have this app that has both an admob banner ad and an interstitial ad. The banner runs fine on all screens. The interstitial ad is only supposed to load on one screen --
You are attempting to present your interstitial before it has a chance to load. Your timer
fires func presentInterstitial
after one second. Change this to a larger number to give the interstitial time to load.
import UIKit
import GoogleMobileAds
class ViewController: UIViewController, GADInterstitialDelegate {
var admobInterstitial : GADInterstitial?
var timer : NSTimer?
override func viewDidLoad() {
super.viewDidLoad()
admobInterstitial = createAndLoadInterstitial()
timer = NSTimer.scheduledTimerWithTimeInterval(5.0, target:self, selector: Selector("presentInterstitial"), userInfo: nil, repeats: false)
}
func createAndLoadInterstitial()->GADInterstitial {
var interstitial = GADInterstitial(adUnitID: "yourAdMobADUnitID")
interstitial.delegate = self
interstitial.loadRequest(GADRequest())
return interstitial
}
func presentInterstitial() {
if let isReady = admobInterstitial?.isReady {
admobInterstitial?.presentFromRootViewController(self)
}
}
func interstitial(ad: GADInterstitial!, didFailToReceiveAdWithError error: GADRequestError!) {
println("interstitialDidFailToReceiveAdWithError:\(error.localizedDescription)")
admobInterstitial = createAndLoadInterstitial()
}
On a side note, you should not give a local variable the same name as a global variable.