ios - 需要帮助在 Spritekit iOS 游戏中集成插页式广告

标签 ios swift xcode admob

我正在使用 Xcode 和 SpriteKit 制作游戏,我正在使用 admob 集成广告,并且所有代码都适用于横幅广告,并且也能够让插页式广告正常运行。我的问题是告诉游戏何时显示插页式广告。广告在 GameViewController 中,但我需要从 GameScene.swift 调用 showAd() 方法 我将如何从 GameScene 中的 GameViewController 调用函数。感谢您提供任何帮助,在此先感谢 Zach。

最佳答案

在您的 GameViewController 中,在 viewWillLayoutSubviews 中设置一个通知观察器,如下所示:

override func viewWillLayoutSubviews() {

    NotificationCenter.default.addObserver(self, selector: #selector(self.showAd), name: NSNotification.Name(rawValue: "showAd"), object: nil)

}

然后在您的 GameScene 中,当您希望运行 GameViewController 中的函数时调用它:

NotificationCenter.default.post(name: NSNotification.Name(rawValue: "showAd"), object: nil)

请记住,您需要在 GameViewController 中调用一个函数。 showAd 只是您希望在 GameViewController 中运行的任何功能的占位符。

希望这对您有所帮助!

关于ios - 需要帮助在 Spritekit iOS 游戏中集成插页式广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40145907/

相关文章:

iphone - 如何从图像中获取单个实体?

swift - cocoa 应用程序 : how to close a window without terminating the app?

swift - 完美,快速,从处理程序中的请求获取服务器地址

ios - 滚动时水平 collectionView 卡住

ios - 使用 https ://asmx-based service with Monotouch

ios - 平台有问题吗? (Cocos2D)

ios - 在具有多个 TableView 的 View Controller 中删除 UITableView 行(Swift)

iphone - 当我在 iphone sdk 中发推文时应用程序崩溃

xcode - 使用其他人的开发者证书签署 iOS 应用程序

ios - MobileVLCKit 不编译