Intersitials Swift ads are not displayed

2

I am developing an application in Swift and after implementing Admob's Intersitials I can not get it displayed. This is my code, what can happen?

class single_noticia: UIViewController, GADInterstitialDelegate {

var interstitial: GADInterstitial!


override func viewDidLoad() {
   super.viewDidLoad()

    self.interstitial = GADInterstitial(adUnitID: "mipub")

    let request = GADRequest()
    self.interstitial.loadRequest(request)

    let progressHUD = MBProgressHUD.showHUDAddedTo(self.view, animated: true)
    progressHUD.labelText = "Preguntando en Secretaría"
    progressHUD.mode = .Indeterminate

    //Alamofire JSON GET

    dispatch_async(dispatch_get_main_queue(), {
            MBProgressHUD.hideAllHUDsForView(self.view, animated: true)
            self.interstitial.presentFromRootViewController(self)
        })

}

In the console I am receiving the following error

  

Google Can not present interstitial. It is not ready.

    
asked by Javi Rando 09.04.2016 в 16:07
source

2 answers

1

First you have to initialize the ad with a adUnitID valid

self.interstitial = GADInterstitial(adUnitID: "ca-app-pub-XXXXXXXXXXXXX")
let request = GADRequest()

The one you are defining, "mipub" is not valid:

GADInterstitial(adUnitID: "mipub")

You must also define the id of the test device, if you are in the development stage:

request.testDevices = ["XXXXXXXXXXXXXXXXXXXX"]
self.interstitial.loadRequest(request)

You can validate to see if your ad is ready to be displayed:

 if self.interstitial.isReady {
    self.interstitial.presentFromRootViewController(self)
  }

You can consult the documentation for more details Announcements interstitial (English)

    
answered by 11.04.2016 в 00:58
0

Ads of type Interstitial have enough content and are slow to load x time. That is why as soon as you open the application, you are probably not ready to show up. For this reason, it is not advisable to show it as soon as you open the UIViewController but to show it after an action or event to give it time to load.

On the other hand, you have a function to verify that you are ready to show up like this:

if self.interstitial.isReady {
    self.interstitial.presentFromRootViewController(self)
}

So that when you want to show the ad, if you are ready, you show it, and if it is not (for example, there is no connection) you do not show it.

UPDATE 1

If it does not work, you can implement the GADInterstitialDelegate delegate and use the following method to show the ad when it has been downloaded:

func interstitialDidReceiveAd(ad: GADInterstitial!) {

    ad.presentFromRootViewController(self)

}

Finally, verify the% test_co_counter by setting the following property:

request.testDevices = ["xxxxxxxxxx"] // Donde las x son el identificador
    
answered by 10.04.2016 в 10:27