我目前正在spritekit
上将广告整合到我的游戏中,我有一个按钮,如果单击该按钮,用户可以获得免费的硬币来观看广告。但是,此操作仅在广告加载后运行,问题在于按钮仍然存在。我希望在广告尚未加载时隐藏按钮,并在广告加载后显示。我从视图控制器中删除了无关的代码。
import UIKit
import SpriteKit
import GameplayKit
import GoogleMobileAds
class GameViewController: UIViewController, GADBannerViewDelegate, GADRewardBasedVideoAdDelegate {
@IBOutlet weak var bannerView: GADBannerView!
@IBOutlet weak var playRewardAd: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
GADRewardBasedVideoAd.sharedInstance().load(GADRequest(),
withAdUnitID: "ca-app-pub-3940256099942544/1712485313")
GADRewardBasedVideoAd.sharedInstance().delegate = self
bannerView.adUnitID = "ca-app-pub-3940256099942544/2934735716"
bannerView.rootViewController = self
bannerView.load(GADRequest())
@IBAction func playVideoAd(_ sender: Any) {
if GADRewardBasedVideoAd.sharedInstance().isReady == true {
GADRewardBasedVideoAd.sharedInstance().present(fromRootViewController: self)
}
}
func rewardBasedVideoAdDidClose(_ rewardBasedVideoAd: GADRewardBasedVideoAd) {
GADRewardBasedVideoAd.sharedInstance().load(GADRequest(),
withAdUnitID: "ca-app-pub-3940256099942544/1712485313")
}
func rewardBasedVideoAd(_ rewardBasedVideoAd: GADRewardBasedVideoAd,
didRewardUserWith reward: GADAdReward) {
coinNumber = coinNumber + 100
defaults.set(coinNumber, forKey: "coinsSaved")
coinLabel.text = "\(coinNumber)"
}
}