如何将承认插页式广告整合到 swift 3. 它是一个虚拟按钮

How can i integrate an admit interstitial Ad into swift 3. It is a virtual button

code of my pause menu如何将承认插页式广告整合到swift 3. 它是一个虚拟按钮。这是我的暂停屏幕的样子 like:import SpriteKit

让BUTTON_DISTANCE: CGFloat = 15 让 BACKGROUND_COLOR = UIColor(红色: 255, 绿色: 255, 蓝色: 255, alpha: 0.2)

class暂停菜单{ 让resumeButton:按钮 让 resetButton: 按钮 让菜单按钮:按钮 让根:SKNode = SKNode() 让 gameDelegate: GameDelegate 让背景:SKSpriteNode

init(scene: SKScene, delegate: GameDelegate) {
    self.gameDelegate = delegate
    root.position = CGPoint(x: scene.frame.midX, y: scene.frame.midY)
    root.zPosition = 5

    resumeButton = Button(scene: scene, parent: root, text: "Resume",
                          x: 0, y: DEFAULT_BUTTON_SIZE.height + BUTTON_DISTANCE,
                          action: gameDelegate.gameResumed)
    resetButton = Button(scene: scene, parent: root, text: "Reset",
                          x: 0, y: 0, action: gameDelegate.gameReseted)
    menuButton = Button(scene: scene, parent: root, text: "Menu",
                          x: 0, y: -(DEFAULT_BUTTON_SIZE.height + BUTTON_DISTANCE),
                          action: gameDelegate.returnMenu)
    background = SKSpriteNode()
    background.size = scene.size
    background.position = CGPoint(x: 0, y: 0)
    background.color = BACKGROUND_COLOR

    root.addChild(background)

    hide()
    scene.addChild(root)
}

func touch(_ touch: UITouch) {
    resumeButton.press(touch)

    resetButton.press(touch)
    menuButton.press(touch)
}

func release(_ touch: UITouch) {
    resumeButton.release(touch)
    resetButton.release(touch)
    menuButton.release(touch)
}

func hide() {
    root.isHidden = true
}

func show() {
    root.isHidden = false
}

}

我希望在您点击休息按钮时显示广告。 -谢谢赞恩

所以您想要做的是 运行 一个功能(显示广告)来自您的 GameViewController 每当您的一个场景中的按钮被按下时。为此,您需要执行以下操作:

在您的 GameViewController 中,在 viewWillLayoutSubviews 中设置通知观察器并设置显示广告的函数:

override func viewWillLayoutSubviews() {

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

}

func showAd() {

    //Code to show the interstitial ad

}

然后在您的场景中,当您希望 GameViewController 中的函数为 运行:

时调用此函数
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "showAd"), object: nil)

按下按钮时,您可以将此代码放在场景中 运行。