[英]interstitialWillDismissScreen only being called once
我在迅速的項目中使用了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")
}
}
我假設loadAd()創建了一個新實例? 您需要在新實例上設置委托:
func interstitialWillDismissScreen(ad: GADInterstitial!) {
interstitial = loadAd()
interstitial.delegate = self // <-- You forgot this.
print("loading new ad")
}
實際上,您可能應該在loadAd()中設置委托,因為它是此類的實例成員。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.