0
我在我的swift項目中使用Admob插頁式廣告,並且無法重新加載廣告。第一個插頁式廣告顯示效果良好,並且在調用interstitialWillDismissScreen時,它會退出遊戲並重新加載新的插頁式廣告。但是,不會再次調用interstitialDidReceiveAd和interstitialWillDismissScreen,因此在顯示第二個廣告之後,不會有其他廣告通過。我錯過了什麼?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")
}
}
謝謝!那就是訣竅。 –