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()
    }
}
Daniel Storm
  • 18,301
  • 9
  • 84
  • 152

1 Answers1

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
}
Memon Irshad
  • 972
  • 1
  • 8
  • 17
  • 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? – Anthony Lorena Tasca May 16 '15 at 06:46
  • use enabled properties of button ex button.enabled = true or false – Memon Irshad May 16 '15 at 06:54