2017-05-09 18 views
0

今はフルページ広告を1回だけ表示しています。私が戻ってボタンをもう一度押すと、それは表示されません。私はボタンがクリックされたままになっていることを表示したい。私は自分のAdMobをFirebaseプロジェクトに繋ぎました。インタースティシャル広告のAdMob広告をボタンがクリックされたあとに表示する方法

class FirstViewController: UIViewController, UIAlertViewDelegate { 


var interstitial: GADInterstitial! 

@IBAction func loadAd(_ sender: Any) { 

    if (interstitial.isReady){ 
     interstitial.present(fromRootViewController: self) 
    } 
} 

override func viewDidLoad() { 

    interstitial = GADInterstitial(adUnitID: "ca-app-pub-11111111/9758796532") 
    let request = GADRequest() 
    interstitial.load(request) 

    super.viewDidLoad() 

} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

}

+0

1つのだけの事は(viewwiiappearにGADInterstitialリクエストを作成します)あなたの問題が解決します –

答えて

0

あなたは毎回GADリクエストを作成する必要があります。

GADInterstitialは1回限りの使用オブジェクトです。つまり、 インタースティシャルが表示されたら、hasBeenUsedはtrueを返し、インタースティシャル は別の広告を読み込むことができません。別のインタースティシャルをリクエストするには、 に新しいGADInterstitialオブジェクトを作成する必要があります。上記のようなベストプラクティス は、作成を処理するヘルパーメソッドを持ち、 インタースティシャルを読み込むことです。

@IBAction func loadAd(_ sender: Any) { 
     interstitial = GADInterstitial(adUnitID: "ca-app-pub-11111111/9758796532") 
     interstitial.delegate = self 
     let request = GADRequest() 
     interstitial.load(request) 

    } 

ながらあなたはデリゲートメソッドで提示する必要が正常にロードされ

optional func interstitialDidReceiveAd(_ ad: GADInterstitial!){ 
    if (interstitial.isReady){ 
      interstitial.present(fromRootViewController: self) 
     } 
} 

optional func interstitialWillDismissScreen(_ ad: GADInterstitial!){ 
     interstitial.delegate = nil 
     interstitial = nil 
} 

optional func interstitialDidFail(toPresentScreen ad: GADInterstitial!){ 
    interstitial.delegate = nil 
    interstitial = nil 
    } 

より:https://firebase.google.com/docs/admob/ios/interstitial

0

作成し、次のロードリクエストを作る我々はに持っている間質を却下インタースティシャル広告。

func interstitialDidDismissScreen(_ ad: GADInterstitial) { 
    interstitial = createAndLoadInterstitial() 
} 

別の間隙を割り当てるのに最適な場所はinterstitialDidDismissScreenである:GADInterstitialDelegate上のメソッドの次の間隙は、すぐ前の1が却下されるとロードを開始するように。あなたも、独自のヘルパーメソッドに間質初期化を壊す検討することがあります。

出典:https://firebase.google.com/docs/admob/ios/interstitial

関連する問題