Marshall D
Marshall D

Reputation: 454

AdMob Interstitial Ad never becoming "ready"

I'm using Xcode 7.3, Swift, SpriteKit, and AdMob. I'm attempting to display an Interstitial ad, but no matter how long I wait the request is never filled and self.interstitial.isReady always is false. Here is my code:

import UIKit
import SpriteKit
import GoogleMobileAds

class GameViewController: UIViewController {

    var interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910")

    override func viewDidLoad() {
        super.viewDidLoad()
        let request = GADRequest()
        // Requests test ads on test devices.
        request.testDevices = ["2077ef9a63d2b398840261c8221a0c9b"]
        self.interstitial.loadRequest(request)
        }
    func displayAd() {
        print(self.interstitial.isReady)
        if self.interstitial.isReady {
            self.interstitial.presentFromRootViewController(self)
        }
    }
}

In another swift file I'm calling GameViewController().displayAd(). This always prints false since interstitial.isReady is never true. *A possible problem - I might be using the wrong test adUnitId or the request.testDevices is not being set to the correct thing.

Why is it that this request wont fill?

Upvotes: 0

Views: 1605

Answers (1)

Marshall D
Marshall D

Reputation: 454

For those reading this at a later time I fixed it, there were two problems:

I'm not using an actualy Ad, so request.testDevices should not be set to anything

Additionally, when I call GameViewController().displayAd(), I'm making a new instance of GameViewController, and it has to be the original. To avoid this I made a variable that referenced GameViewController's self, then did variable.displayAd()

Upvotes: 0

Related Questions