Why Is My Admob Interstitial Working Fine in Xcode Simulator But Not on My Test Devices

Why is my AdMob interstitial working fine in Xcode Simulator but not on my test devices?

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()
}

How to show a real Admob ad rather than the test ad?

Do this:

1-remove "request.testDevices = ["2077ef9a63d2b398840261c8221a0c9b"]

2- Create an Admob account on google's website, then create an app in your account,then, replace the default adUnitID given in the google's tutorial with the one in the created app.

3- Then, instead of test ad, you might get a full black screen ad. This one is because it takes a few hours before google starts to send real ads. Hope that helps.

Admob works for interstitial, but not for the banner

they use the same Ad unit ID

This is your problem. Each ad needs its own unique Ad unit ID. One Ad unit ID for the interstitial ad, and one Ad unit ID for the banner ad in your case. The reason the interstitial works and the banner does not is because you have the correct Ad unit ID set for your interstitial whereas your banner can not use an interstitial Ad unit ID.

  1. Go to AdMob.com
  2. Click Monetize
  3. Click "YourApplicationName"
  4. Click New Ad Unit
  5. Select Banner and follow the setup
  6. Implement the newly generated Ad unit ID for your banner in your application


Related Topics



Leave a reply



Submit