AdMob - "Ad wasn't ready" error with real unit ID (Swift)

Viewed 668

I try to setup interstitial ads in my app. If I use a test unit ID, ad shows fine, but if I try to use the real unit ID, I see the error "Ad wasn't ready". What I do wrong? Thank for any help! My code:

import UIKit
import GoogleMobileAds

class ViewController: UIViewController {
var interstitial: GADInterstitial!

override func viewDidLoad() {
   super.viewDidLoad()
   interstitial = createAndLoadInterstitial()
}

override func viewWillAppear(_ animated: Bool) {
   super.viewWillAppear(animated)
   DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
    if self.interstitial.isReady {
        self.interstitial.present(fromRootViewController: self)
    } else {
        print("Ad wasn't ready")
    }
   }
}

func createAndLoadInterstitial() -> GADInterstitial {
    let interstitial = GADInterstitial(adUnitID: "AdMob Real Unit ID")
    interstitial.delegate = self
    let request = GADRequest()
    GADMobileAds.sharedInstance().requestConfiguration.testDeviceIdentifiers = ["my device ID from console"]
    interstitial.load(request)
    return interstitial
}
}

extension ViewController: GADInterstitialDelegate {
func interstitialDidDismissScreen(_ ad: GADInterstitial) {
    interstitial = createAndLoadInterstitial()
}
}

Console: console

2 Answers

Launching interstitial ad immediately after page load is disallowed. Refer Disallowed Interstitial implementation policy https://support.google.com/admob/answer/6201362?hl=en

A common issue is that even though you may intend for the ad to load in between page content, the ad itself appears shortly after a new page of content has loaded due to carrier latency. To prevent this from happening, we recommend you pre-load the interstitial in advance. To learn more about how to pre-load your interstitial ad, please follow the AdMob Interstitial Ad developer guidelines for apps developed for Android and iOS.

Only load the ad on viewDidLoad () https://developers.google.com/admob/ios/interstitial

class ViewController: UIViewController {

  var interstitial: GADInterstitial!

  override func viewDidLoad() {
    super.viewDidLoad()
    interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910")
    let request = GADRequest()
    interstitial.load(request)
  }
}

and then Interstitials should be displayed during natural pauses in the flow of an app. Between levels of a game is a good example, or after the user completes a task.

@IBAction func doSomething(_ sender: AnyObject) {
  ...
  if interstitial.isReady {
    interstitial.present(fromRootViewController: self)
  } else {
    print("Ad wasn't ready")
  }
}

Solved: To display your ad units, your AdMob account must be verified. You must see message in the Google AdMob Console:

Your account is approved
Congratulations! We've verified your account information and your ad serving is enabled.
Related