Exibir anúncios intersticiais da Admob entre cenas no Swift SpriteKit
Gostaria de saber como configurar os anúncios intersticiais da Admob quando apresentar meu GameOverScene. O que devo fazer para mostrar os anúncios apenas às vezes quando o jogo termina? E como implemento isso no Swift?
Estou me referindo a este postComo chamar um anúncio intersticial da admob usando swift, spritekit e xcode? mas eu gostaria de saber como chamar os anúncios entre as cenas.
EDITAR Aqui está o código que usei para apresentar o anúncio
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 um timer para verificar constantemente se o gameOverScene foi apresentado. Quando o gameOverScene É apresentado, eu atribuotrue
ao"adToBeShown"
bool. Esse não é o melhor método, então alguém poderia me dizer como chamar o anúncio diretamente quando uma cena é apresentada?