4
votes

I'm trying to reward a user for watching a video with AdMob. Although I couldn't find any tutorial on the subject, I found these two classes in the documentation:

GADRewardBasedVideoAd

GADRewardBasedVideoAdDelegate

I've set up the display of a GADRewardBasedVideoAd with the following View Controller code:

class MarketController: UIViewController, GADRewardBasedVideoAdDelegate {


override func viewDidLoad() {
    super.viewDidLoad()

    GADRewardBasedVideoAd.sharedInstance().delegate = self
    let request = GADRequest()
    // Requests test ads on test devices.
    request.testDevices = ["2077ef9a63d2b398840261c8221a0c9b"]
    GADRewardBasedVideoAd.sharedInstance().loadRequest(request, withAdUnitID: "ca-app-pub-3940256099942544/4411468910")
}



// MARK: Daily Reward Button Delegate

@IBAction func playVideoClicked() {
    if GADRewardBasedVideoAd.sharedInstance().ready {
        GADRewardBasedVideoAd.sharedInstance().presentFromRootViewController(self)
    }
}


// MARK: GADRewardBasedVideoAdDelegate

func rewardBasedVideoAdDidStartPlaying(rewardBasedVideoAd: GADRewardBasedVideoAd!) {
    MediaPlayer.pauseBackgroundMusic()
    print("Reward Video: Started")
}

func rewardBasedVideoAdDidClose(rewardBasedVideoAd: GADRewardBasedVideoAd!) {
    MediaPlayer.startBackgroundMusic()
    requestLoadAd()
    print("Reward Video: Complete")
}

func rewardBasedVideoAdWillLeaveApplication(rewardBasedVideoAd: GADRewardBasedVideoAd!) {
    requestLoadAd()
    print("Reward Video: Will leave application")
}

}

When I press the button to trigger the code in the "playVideoClicked" function, I just see a regular test interstitial (no video) and the "rewardBasedVideoDidStartPlaying" function never gets called. When I close the interstitial the "rewardBasedVideoAdDidClose" function is called, though. Does this mean I did something wrong, or does AdMob just not display test videos?

Also, how do I configure this ad as a Reward Video in the AdMob developer console?

1
Thanks for your interest, but those classes relate to an experimental feature and cannot/should not be used right now.RedBrogdon
Just found this class and I was interested in using it as well. Where did you get this info that it can't be used right now? Google docs provides all the details about the implementation: developers.google.com/admob/ios/api/…tomDev
Hi, did you find a workaround to your problem?gionti
No, I never found a workaround using AdMob. Since I was designing a game, I switched to Chartboost to display reward videos.kmell96

1 Answers

2
votes

Change request.testDevices = ["2077ef9a63d2b398840261c8221a0c9b"] to request.testDevices = [kGADSimulatorID] and it should be working.