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:
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?