Mostrar anuncios intersticiales de Admob entre escenas en Swift SpriteKit
Me gustaría saber cómo configurar anuncios intersticiales de Admob cuando presento mi GameOverScene. ¿Qué debo hacer para mostrar los anuncios solo a veces cuando termina el juego? ¿Y cómo implemento esto en Swift?
Me refiero a esta publicación¿Cómo llamar a un anuncio intersticial admob usando swift, spritekit y xcode? pero me gustaría saber cómo llamar a los anuncios entre escenas.
EDITAR Aquí está el código que utilicé para presentar el anuncio.
class GameViewController: UIViewController, GADInterstitialDelegate {
var interstitial = GADInterstitial()
var intersitialRecievedAd = false
let defaults = NSUserDefaults.standardUserDefaults()
override func viewDidLoad() {
super.viewDidLoad()
interstitial.delegate = self
self.interstitial = createAndLoadAd()
let timer = NSTimer.scheduledTimerWithTimeInterval(0.5, target: self, selector: "checkIfAdIsToBeDisplayed:", userInfo: nil, repeats: true)
//Scene implementation, boring stuff, got nothing to do with the ads...
...
}
func checkIfAdIsToBeDisplayed(timer:NSTimer) {
if defaults.boolForKey("adToBeShown") == true && intersitialRecievedAd == true {
showInterstitial()
defaults.setBool(false, forKey: "adToBeShown")
intersitialRecievedAd = false
} else {
}
}
func interstitialDidReceiveAd(ad: GADInterstitial!) {
intersitialRecievedAd = true
}
func createAndLoadAd() -> GADInterstitial {
var ad = GADInterstitial(adUnitID: "...")
ad.delegate = self
let request = GADRequest()
request.testDevices = ["..."]
ad.loadRequest(request)
return ad
}
func showInterstitial(){
if self.interstitial.isReady {
self.interstitial.presentFromRootViewController(self)
self.interstitial = createAndLoadAd()
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Release any cached data, images, etc that aren't in use.
}
override func prefersStatusBarHidden() -> Bool {
return true
}
}
Este código usa un temporizador para verificar constantemente si se ha presentado el gameOverScene. Cuando se presenta el gameOverScene, asignotrue
al"adToBeShown"
bool Este no es el mejor método, entonces, ¿alguien podría decirme cómo llamar directamente al anuncio cuando se presenta una escena?