添加 AdMob 插页式广告时出错 Swift

Errors when adding AdMob interstitial Swift

我正在尝试添加 AdMob 插页式广告,但我不知道如何操作。我试过 YouTube 上的教程,但收到 2 个错误。

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()
    }
}

添加此代码

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

var request = GADRequest()

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

return ad
}