我对 AdMob 还不太熟悉,所以我不知道到底发生了什么。我正在尝试将插页式广告添加到我的 SpriteKit 游戏中,并且我确实按照 Google AdMob 网站上的文档将这种广告格式实现到我的应用程序中。然而,每当我尝试遵循它并从 Root View Controller 呈现它时,它最终都会给我一个错误。 This is where the issue currently is
我个人无法弄清楚发生了什么。我非常感谢大家能提供的所有帮助。谢谢。
最佳答案
您正在尝试将其加载到场景中。 SKScene
不是 UIViewController
。您必须在设置 SKView
的 View Controller 中初始化并加载广告:
var yourAd: GADBannerView!
override func viewDidLoad() {
super.viewDidLoad()
let scene = YourScene(size: CGSize(width: 1024.0, height: 768.0))
// Configure the view.
let skView = self.view as! SKView
skView.presentScene(scene)
// Initialize yourAd here
}
然后,如果您将其作为 View Controller 属性,则可以隐藏它并显示它,或者在场景中对其执行任何您想要的操作。因此,假设此代码位于您的场景内:
let gameViewController = view.window?.rootViewController as! YourViewControllerClass
gameViewController.yourAd.hidden = false
// or present interstitial or whatever you want to do
关于ios - 我遇到了一个奇怪的 SpriteKit AdMob 错误,有点令人困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44706441/