2017-05-09 1 views
0

À l'heure actuelle, l'annonce ne s'affiche qu'une seule fois. Quand je reviens et appuyez sur le bouton à nouveau, il ne s'affiche pas. Je voudrais qu'il montre des heures supplémentaires mon bouton est cliqué. Mon AdMob est connecté à mon projet Firebase.Comment puis-je faire en sorte que mon annonce adMob interstitielle s'affiche au bout d'un certain temps?

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

Il suffit de faire une chose demande de création GADInterstitial sur viewwiiappear() votre problème à résoudre –

Répondre

0

Vous devez créer GAD demande à chaque fois.

GADInterstitial est un objet à utilisation unique. Cela signifie qu'une fois qu'un interstitiel est affiché, hasBeenUsed renvoie true et l'interstitiel ne peut pas être utilisé pour charger une autre annonce. Pour demander un autre interstitiel, , vous devez créer un nouvel objet GADInterstitial. La meilleure pratique, comme indiqué ci-dessus, est d'avoir une méthode d'assistance pour gérer la création et chargement d'un interstitiel.

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

    } 

Et alors chargé vous avez besoin avec succès à présenter à la méthode des délégués

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 
    } 

Plus: https://firebase.google.com/docs/admob/ios/interstitial

0

Rejetant l'interstitiel nous devons créer et faire une demande de charge pour la prochaine annonces interstitielles.

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

Le meilleur endroit pour allouer une autre interstitiel est dans la interstitialDidDismissScreen: méthode sur GADInterstitialDelegate afin que la prochaine commence interstitiels chargement dès que le précédent est rejeté. Vous pouvez même envisager sortir l'initialisation interstitielle dans sa propre méthode d'assistance:

Source: https://firebase.google.com/docs/admob/ios/interstitial