Search code examples
swiftadmobinterstitial

Swift Admob reward based video ad integration and testing


I've successfully been able to integrate both banner ads and image based interstitial ads into my applications with no problems.

I'm considering adding a reward based video ad however I'm not sure if I can simply set up the code as per the interstitial ad but change the adUnitID to that of the rewarded video ad I set up in Admob?

When I do just that the test ad showing an interstitial therefore I can't tell if a video would display.

I'm finding very little guidance to follow online with regard to setting it up this way.

This is what I currently use:

    func loadAndShow3() {



    let request = GADRequest()
    request.testDevices = [kGADSimulatorID, "XXXX"]
    myAd = GADInterstitial(adUnitID: "XXXX")
    myAd.delegate = self
    myAd.load(request)



}

func interstitialDidReceiveAd(_ ad: GADInterstitial) {

    if (self.myAd.isReady) {

        myAd.present(fromRootViewController: self)



    }
 func displayAd() {



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


}

Solution

  • Your current code would not work. You would have to make a new request for a GADRewardBasedVideoAd instead of the GADRequest(). There is a really good tutorial made by Google at how to do that attached below. If you follow the tutorial it's a rather straight forward solution. Best of luck to you.

    Google's tutorial.