在用户与 iAd 交互时暂停游戏 Swift

Pause game while user interacts with iAd Swift

我目前不明白下面链接的问题的已批准解决方案:

use a UITapGestureRecognizer instead. Check if recognizer.view != adBanner

我在 Sprite Kit 游戏中遇到了同样的问题,但在 Swift 中,我不确定如何实施已批准的解决方案。有人可以提供代码示例吗?

这是我的代码:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    for touch in touches {
        // If iAd banner has been tapped, do not start the game

        // Else game starts
    }
}

func adStopsGame(tapGesture: UITapGestureRecognizer) {
    print("Game stopped")
}

您需要使用 bannerViewActionShouldBegin(_:willLeaveApplication:).

This method is called when the user taps the banner view. Your application controls whether the action is triggered. To allow the action to be triggered, return true. To suppress the action, return false. Your application should almost always allow actions to be triggered; preventing actions may alter the advertisements your application sees and reduce the revenue your application earns through iAd.

有关 ADBannerView 委托方法的完整列表,请参阅:ADBannerViewDelegate Protocol Reference