Admob奖励视频只会出现一次,然后必须重新启动应用

时间:2017-04-30 20:04:37

标签: ios swift admob

我已将admob奖励视频整合到我的应用中。

当应用程序启动时,我点击了"观看视频"按钮奖励视频播放正常。

然而,如果我"关闭视频"然后尝试观看视频"再次它不起作用。

视频完成后如果我尝试观看视频"再次它不起作用。

一旦视频无法再次打开,它就会被打开。

所以在SKScene中我有:

 func videoAd() {

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

在View控制器中:

    func loadAndShow3() {

    GADRewardBasedVideoAd.sharedInstance().delegate = self

    GADRewardBasedVideoAd.sharedInstance().present(fromRootViewController: self)

}

func rewardBasedVideoAdDidReceive(_ rewardBasedVideoAd: GADRewardBasedVideoAd) {


    if GADRewardBasedVideoAd.sharedInstance().isReady {



        GADRewardBasedVideoAd.sharedInstance().present(fromRootViewController: self)
    }


}


func rewardBasedVideoAd(_ rewardBasedVideoAd: GADRewardBasedVideoAd, didRewardUserWith reward: GADAdReward) {

    let oldCoin = UserDefaults.standard.integer(forKey: "COINSCORE")
    let newCoin = oldCoin + 20
    UserDefaults.standard.set(newCoin, forKey: "COINSCORE")
    UserDefaults.standard.synchronize()

    if let view = self.view as! SKView? {

        if let scene3 = GameOverMenu(fileNamed: "Gameover") {

            scene3.viewController = self
            scene3.scaleMode = .aspectFill
            view.presentScene(scene3)

            scene3.coinLabel.removeFromParent()
            scene3.createCoinScore()



        }
    }


}

在代表中我有:

 let request = GADRequest()
    GADRewardBasedVideoAd.sharedInstance().load(request, withAdUnitID: "ca-app-pub-3940256099942544/1712485313")

2 个答案:

答案 0 :(得分:4)

您需要实现GADRewardBasedVideoAd的委托方法。

具体做法是:

func rewardBasedVideoAdDidClose(_ rewardBasedVideoAd: GADRewardBasedVideoAd) {
    print("Reward based video ad is closed.")
}

您应该在此处构建新的GADRewardBasedVideoAd并请求新广告。

答案 1 :(得分:1)

修复了,不得不在视图控制器中随机播放一些代码并实现Daniel的答案

 override func viewDidLoad() {


    super.viewDidLoad()

    GADRewardBasedVideoAd.sharedInstance().delegate = self
    let request = GADRequest()
    GADRewardBasedVideoAd.sharedInstance().load(request, withAdUnitID: "ca-app-pub-3940256099942544/1712485313")


func loadAndShow3() {


    if GADRewardBasedVideoAd.sharedInstance().isReady {

        GADRewardBasedVideoAd.sharedInstance().present(fromRootViewController: self)
    }

}




}

func rewardBasedVideoAdDidReceive(_ rewardBasedVideoAd: GADRewardBasedVideoAd) {


}


func rewardBasedVideoAd(_ rewardBasedVideoAd: GADRewardBasedVideoAd, didRewardUserWith reward: GADAdReward) {

    let oldCoin = UserDefaults.standard.integer(forKey: "COINSCORE")
    let newCoin = oldCoin + 20
    UserDefaults.standard.set(newCoin, forKey: "COINSCORE")
    UserDefaults.standard.synchronize()

    if let view = self.view as! SKView? {

        if let scene3 = GameOverMenu(fileNamed: "Gameover") {

            scene3.viewController = self
            scene3.scaleMode = .aspectFill
            view.presentScene(scene3)

            scene3.coinLabel.removeFromParent()
            scene3.createCoinScore()



        }
    }


}

func rewardBasedVideoAdDidClose(_ rewardBasedVideoAd: GADRewardBasedVideoAd) {


  let request = GADRequest()
   GADRewardBasedVideoAd.sharedInstance().load(request, withAdUnitID: "ca-app-pub-3940256099942544/1712485313")


}