我有这些facebook插页式广告,当我在我的GameScene中调用它们时,它们不会显示出来。当我在GameViewController中调用它们而不是在我的GameScene中时它们完美地工作。有人能告诉我我的代码出了什么问题吗?
grails-app/conf
答案 0 :(得分:0)
你试试:
//GameViewController.swift
class GameViewController: UIViewController, FBInterstitialAdDelegate {
let interstitialFBAD: FBInterstitialAd = FBInterstitialAd(placementID: "65543456456456_454345345454534")
var scene: GameScene!
override func viewDidLoad() {
super.viewDidLoad()
let skView = view as! SKView
skView.multipleTouchEnabled = false
scene = GameScene(size: skView.bounds.size)
scene.scaleMode = .AspectFill
scene.view?.userInteractionEnabled = true
skView.presentScene(scene)
scene.gvcDelegate = self
}
//GameScene.swift
class GameScene: SKScene {
gvcDelegate: GameViewController?
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch in touches {
let location = touch.locationInNode(self)
let node = self.nodeAtPoint(location)
if node.name == "retry" {
gvcDelegate.loadFBInterstitialAd()
}
}
}
古德勒克!
答案 1 :(得分:0)
在GameViewController的viewDidLoad
注册中发送通知,稍后在GameScene中发布通知,希望广告出现。
所以您的viewDidLoad
将有以下额外的行
NSNotificationCenter.defaultCenter().addObserver(self, selector: "loadFBInterstitialAd", name: "loadAd", object: nil)
然后在Gamescene中编写一个方法
func showAdNow() {
NSNotificationCenter.defaultCenter().postNotificationName("loadAd", object: nil)
}
现在在Gamescene.swift中替换
行GameViewController().loadFBInterstitialAd()
带
showAdNow()