Rewarded

Rewarded ads are ads that users have the option of interacting with in exchange for in-app rewards. This guide shows you how to integrate rewarded ads from Adx3 into an iOS app.

Prerequisites

Always test with test ads

When building and testing your apps, make sure you use test ads rather than live, production ads. Failure to do so can lead to suspension of your account. The easiest way to load test ads is to use our dedicated test ad unit ID for app-rewarded ads:

63a573b533f6f

It's been specially configured to return test ads for every request, and you're free to use it in your own apps while coding, testing, and debugging. Just make sure you replace it with your own ad unit ID before publishing your app.

Implementation

The main steps to integrate interstitial ads are:

  • Load an ad.

  • Register for callbacks.

  • Display the ad and handle the event.

Load an ad

Loading an ad is accomplished using the static loadAdWithPlacementID:userId:delegate: method on the Adx3RewardAd class. The load method requires your ad unit ID, a userId object, and a delegate object which gets called when ad loading succeeds or fails. UserId object cannot be passed, nor can your custom user identifier. The below example shows how to load an Adx3RewardAd in your ViewController class.

import UIKit

class ViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        loadRewardAd()
        // Do any additional setup after loading the view.
    }
    
    func loadRewardAd() {
        Adx3RewardAd.sharedManager().load(withPlacementID: "Your Placement ID", userId: "", delegate: self)
    }
}

Register for callbacks

You should rely on the Adx3RewardDelegate (optional) to handle display events and request events. The following code shows how to implement the protocol:

import UIKit

class ViewController: UIViewController, Adx3RewardDelegate {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
}

extension ViewController {
    
    func didFinishLoadingAD(withPlacementID placementID: String!) {
        print("----Interstitial AD Load Finish----")
    }
    
    func didFailToLoadAD(withPlacementID placementID: String!, error: Error!) {
        print("----\(error.debugDescription)----")
    }
    
    func rewardDidShow(forPlacementID placementID: String!, extra: [AnyHashable : Any]!) {
        
    }
    
    func rewardDidClick(forPlacementID placementID: String!, extra: [AnyHashable : Any]!) {
        
    }
    
    func rewardDidClose(forPlacementID placementID: String!, extra: [AnyHashable : Any]!) {
        
    }
    
    func rewardDidEndPlayingVideo(forPlacementID placementID: String!, extra: [AnyHashable : Any]!) {
    
    }
    
    func rewardDidStartPlayingVideo(forPlacementID placementID: String!, extra: [AnyHashable : Any]!) {
        
    }
    
    func rewardFailedToShow(forPlacementID placementID: String!, error: Error!, extra: [AnyHashable : Any]!) {
        
    }
    
    func rewardDidFailToPlayVideo(forPlacementID placementID: String!, error: Error!, extra: [AnyHashable : Any]!) {
        
    }
    
}

Display the ad

Before displaying a rewarded ad to users, you must present the user with an explicit choice to view rewarded ad content in exchange for a reward. Rewarded ads must always be an opt-in experience.

The following code presents the best method for displaying a rewarded ad.

func showRewardAd() {
    if Adx3RewardAd.sharedManager().rewardIsReady() {
        Adx3RewardAd.sharedManager().showReward(in: self, delegate: self)
    }
}

Last updated