2016-07-12 16 views
0

私は迅速なプロジェクトでAdmobインタースティシャルを使用していますが、広告の再読み込みに問題があります。最初のインタースティシャルは正常に表示され、interstitialWillDisissScreenが呼び出されると、ゲームに戻り、新しいインタースティシャルが再ロードされます。ただし、interstitialDidReceiveAdもinterstitialWillDismissScreenも再び呼び出されることはないため、2番目の広告が表示された後、他の広告は表示されません。私は何が欠けていますか?interstitialWillDismissScreenは1回のみ呼び出されます

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

答えて

1

loadAd()は新しいインスタンスを作成すると仮定しますか?あなたは、新しいインスタンスにデリゲートを設定する必要があります。

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

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

    print("loading new ad") 
} 

それは、このクラスのインスタンスメンバーであるため、実際にあなたがおそらく)(loadAdにデリゲートを設定する必要があります。

+0

ありがとうございます!それがトリックでした。 –

関連する問題