Reputation: 259
I'm developing an iOS application using Swift2 and Xcode7. I'm trying to implement AdMob but it doesn't display my interstitial ad.
override func viewDidLoad() {
super.viewDidLoad()
_interstitial = createAndLoadInterstitial()
}
func createAndLoadInterstitial()->GADInterstitial {
let interstitial = GADInterstitial(adUnitID: "interstitial_ID")
let gadRequest:GADRequest = GADRequest()
gadRequest.testDevices = ["test device id"]
interstitial.delegate = self
interstitial?.loadRequest(gadRequest)
return interstitial!
}
func interstitialDidReceiveAd(ad: GADInterstitial!) {
_interstitial?.presentFromRootViewController(self)
}
func interstitial(ad: GADInterstitial!, didFailToReceiveAdWithError error: GADRequestError!) {
print(error.localizedDescription)
}
func interstitialDidDismissScreen(ad: GADInterstitial!) {
_interstitial = createAndLoadInterstitial()
}
I receive this error:
Request Error: No ad to show.
Upvotes: 8
Views: 17628
Reputation: 20196
Request Error: No ad to show.
means that your request was successful but that Admob has no ad to show for your device at this time. The best way to ensure that you always have ads to show is to use mediation so that an unfulfilled request falls through to another ad network. Admob provides good mechanisms to do that.
Upvotes: 16
Reputation: 18908
You should have two Ad Unit ID's. One for your GADBannerView
and one for your GADInterstitial
. Make sure your Ad Unit ID supplied by AdMob for your interstitial is exactly the same as what they've given you. Update to the latest AdMob SDK, currently 7.5.0. Also consider calling presentFromRootViewController(self)
at specific intervals or once the user completes a desired action. The way you have it setup now will keep presenting interstitials one after another because you are sending requests for new interstitials every time one is dismissed and then displaying the interstitial as soon as it receives an ad.
import UIKit
import GoogleMobileAds
class ViewController: UIViewController, GADInterstitialDelegate {
var myInterstitial : GADInterstitial?
override func viewDidLoad() {
super.viewDidLoad()
myInterstitial = createAndLoadInterstitial()
}
func createAndLoadInterstitial()->GADInterstitial {
let interstitial = GADInterstitial(adUnitID: "Your Ad Unit ID")
interstitial.delegate = self
interstitial?.loadRequest(GADRequest())
return interstitial
}
@IBAction func someButton(sender: AnyObject) {
myInterstitial?.presentFromRootViewController(self)
}
func interstitialDidReceiveAd(ad: GADInterstitial!) {
print("interstitialDidReceiveAd")
}
func interstitial(ad: GADInterstitial!, didFailToReceiveAdWithError error: GADRequestError!) {
print(error.localizedDescription)
}
func interstitialDidDismissScreen(ad: GADInterstitial!) {
print("interstitialDidDismissScreen")
myInterstitial = createAndLoadInterstitial()
}
Upvotes: 3