3

I'm attempting to add an AdMob interstitial but I don't know how. I've tried a tutorial on YouTube but I receive 2 errors.

var interstitial: GADInterstitial!

  override func viewDidLoad() {
    super.viewDidLoad()

    self.interstitial = self.createAndLoadAd()

  func createAndLoadAd() -> GADInterstitial {
    var ad = GADInterstitial()
    ad.adUnitID = "myInterstitialID"

    var request = GADRequest()

    request.testDevices = ["2077ef9a63d2b398840261c8221a0c9b"]
    ad.loadRequest(request)

    return ad
}

@IBAction func adButton(sender: AnyObject) {
    if (self.interstitial.isReady)
    {
        self.interstitial.presentFromRootViewController(self)
        self.interstitial = self.createAndLoadAd()
    }
}
2
  • 1
    Can you please specify the errors?
    – Sohel L.
    Commented May 16, 2015 at 4:05
  • i get 2 errors it says init() or use initWithadUnitID() Commented May 16, 2015 at 4:22

1 Answer 1

1

add this code

func createAndLoadAd() -> GADInterstitial {
 var ad = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910")

var request = GADRequest()

request.testDevices = ["2077ef9a63d2b398840261c8221a0c9b"]
ad.loadRequest(request)

return ad
}
2
  • i have another question i made i button in main.storyboard in it shows in all of my skscene i have 3 scenes home, play scene and game over scene and the button show up in all of the scene is there anyway i can make the button disappear in the play scene? Commented May 16, 2015 at 6:46
  • use enabled properties of button ex button.enabled = true or false Commented May 16, 2015 at 6:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.