简体   繁体   English

interstitialWillDismissScreen仅被调用一次

[英]interstitialWillDismissScreen only being called once

I am using Admob interstitials in my swift project and I am having trouble reloading the ads. 我在迅速的项目中使用了Admob插页式广告,但无法重新加载广告。 The first interstitial displays fine, and when interstitialWillDismissScreen is called, it exits back to the game and reloads a new interstitial as it's supposed to. 第一个非页内广告显示正常,当调用interstitialWillDismissScreen时,它退出游戏并按预期加载新的非页内广告。 However, neither interstitialDidReceiveAd nor interstitialWillDismissScreen are called again, so after the second ad is displayed, no other ads come through. 但是,interstitialDidReceiveAd和interstitialWillDismissScreen都不会再次调用,因此在显示第二个广告之后,其他任何广告都不会通过。 What am I missing? 我想念什么?

import GoogleMobileAds

let appDelegate = (UIApplication.sharedApplication().delegate as! AppDelegate)

class GameScene: SKScene, GKGameCenterControllerDelegate, GADInterstitialDelegate {

    var interstitial: GADInterstitial!

    override func didMoveToView(view: SKView) {

        //preload interstitial ad
        if NSUserDefaults.standardUserDefaults().boolForKey("paidToRemoveAds") == false {
            interstitial = loadAd()
        }

        interstitial.delegate = self
    }

    func gameOver() {
        runGoogleAd()
    }

    func loadAd() -> GADInterstitial {
        let ad = GADInterstitial(adUnitID: "ca-app-pub-2963481692578498/7292484569")
        let request = GADRequest()
        request.testDevices = [kGADSimulatorID]
        ad.loadRequest(request)
        return ad
    }

    func runGoogleAd() {
        if interstitial.isReady {
            interstitial.presentFromRootViewController((appDelegate.window?.rootViewController)!)
        }
    }

    func interstitialDidReceiveAd(ad: GADInterstitial!) {
        print("ad loaded")
    }

    func interstitialWillDismissScreen(ad: GADInterstitial!) {
        interstitial = loadAd()
        print("loading new ad")
    }
}

I assume loadAd() creates a new instance? 我假设loadAd()创建了一个新实例? You need to set the delegate on the new instance: 您需要在新实例上设置委托:

func interstitialWillDismissScreen(ad: GADInterstitial!) {
    interstitial = loadAd()

    interstitial.delegate = self  // <-- You forgot this.

    print("loading new ad")
}

Actually you should probably set the delegate in loadAd() since it is an instance member of this class. 实际上,您可能应该在loadAd()中设置委托,因为它是此类的实例成员。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM