【问题标题】:interstitialWillDismissScreen only being called onceinterstitialWillDismissScreen 只被调用一次
【发布时间】:2016-07-12 01:58:58
【问题描述】:

我在我的 swift 项目中使用 Admob 插页式广告,但我无法重新加载广告。第一个插页式广告可以正常显示,当 interstitialWillDismissScreen 被调用时,它会退出游戏并重新加载新的插页式广告。但是 interstitialDidReceiveAd 和 interstitialWillDismissScreen 都没有被再次调用,所以在显示第二个广告后,没有其他广告通过。我错过了什么?

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

【问题讨论】:

    标签: ios swift admob interstitial


    【解决方案1】:

    我假设 loadAd() 创建了一个新实例?您需要在新实例上设置委托:

    func interstitialWillDismissScreen(ad: GADInterstitial!) {
        interstitial = loadAd()
    
        interstitial.delegate = self  // <-- You forgot this.
    
        print("loading new ad")
    }
    

    实际上您应该在 loadAd() 中设置委托,因为它是此类的实例成员。

    【讨论】:

      猜你喜欢
      • 2021-01-04
      • 2019-08-23
      • 2017-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多