Integrate Amazon SDK

Last Updated on: 19 Sep, 2023

To use the APSBidLoader class in your project, copy and paste the code into your Xcode project and add the DTBiOSSDK framework to your project's dependencies.

This code defines a class that provides methods for loading different ads using the DTBiOSSDK framework. The class includes methods for loading banner, interstitial, video, and rewarded video ads, and it uses a completion handler to return the ad response or error to the caller.

To use this class, the caller must first initialize the Amazon SDK using the initializeAmazonSDK method, passing in the app ID for their Amazon account. Once the SDK is initialized, the caller can use the loadBannerAd, loadInterstitialAd, loadVideoAd, and loadRewardedAd methods to load ads of the corresponding type.

The `APSBidLoader` class handles creating a `DTBAdSize` object with the appropriate size and slot ID and then using that object to load the ad using the `DTBAdLoader` class from the DTBiOSSDK framework. If the ad request is successful, the `onSuccess` method of the `DTBAdCallback` protocol is called, and the ad response is passed back to the caller using the completion handler. If the ad request fails, the `onFailure` method is called, and the error information is passed back to the caller. 

INFO

Use the same code for Swift and Objective–c.

import Foundation
import DTBiOSSDK

@objc public class APSBidLoader: NSObject {
    typealias CompletionHandler = (_ apsBidResponse: Any?) -> Void    

    static var isAPSSDKInitialized = false
    private var handler: CompletionHandler

    fileprivate init(completionHandler: @escaping (_: Any) -> Void) {
        self.handler = completionHandler
    }

    private func createAdLoader(with size: DTBAdSize) {
        guard APSBidLoader.isAPSSDKInitialized else {
            print("\(#function): APS SDK is not initialized yet")
            handler(nil)
            return
        }       

        let adLoader = DTBAdLoader()
        adLoader.setAdSizes([size])
        adLoader.loadAd(self)
    }
}

extension APSBidLoader: DTBAdCallback {    

    public func onSuccess(_ adResponse: DTBAdResponse!) {
        handler(adResponse)
    }    

    public func onFailure(_ error: DTBAdError, dtbAdErrorInfo: DTBAdErrorInfo!) {
        print("\(#function): APS failed with error \(error)")
        handler(dtbAdErrorInfo)
    }
}

extension APSBidLoader {   

    @objc static func initializeAmazonSDK(with appId: String) {
        DTBAds.sharedInstance().setAppKey(appId)
        isAPSSDKInitialized = true
    }    

    @objc static func loadBannerAd(with slotId: String, adSize: CGSize, completionHandler: @escaping CompletionHandler) {
        let loader = APSBidLoader(completionHandler: completionHandler)        

        guard let size = DTBAdSize(bannerAdSizeWithWidth: Int(adSize.width),
                                   height: Int(adSize.height),
                                   andSlotUUID: slotId) else {
            print("\(#function): Failed to create an object")
            completionHandler(nil)
            return
        }
        loader.createAdLoader(with: size)
    }    

    @objc static func loadInterstitialAd(with slotId: String, completionHandler: @escaping CompletionHandler) {
        let loader = APSBidLoader(completionHandler: completionHandler)                

        guard let size = DTBAdSize(interstitialAdSizeWithSlotUUID: slotId) else {
            print("\(#function): Failed to create an object")
            completionHandler(nil)
            return
        }
        loader.createAdLoader(with: size)
    }    

    @objc static func loadVideoAd(with slotId: String, completionHandler: @escaping CompletionHandler) {
        let loader = APSBidLoader(completionHandler: completionHandler)                
        guard let size = DTBAdSize(videoAdSizeWithSlotUUID: slotId) else {
            print("\(#function): Failed to create an object")
            completionHandler(nil)
            return
        }
        loader.createAdLoader(with: size)
    }    

    @objc static func loadRewardedAd(with slotId: String, completionHandler: @escaping CompletionHandler) {
        let loader = APSBidLoader(completionHandler: completionHandler)                

        guard let size = DTBAdSize(videoAdSizeWithSlotUUID: slotId) else {
            print("\(#function): Failed to create an object")
            completionHandler(nil)
            return
        }
        loader.createAdLoader(with: size)
    }
}

Initialize Amazon SDK

Initialize the Amazon SDK.

Swift

import UIKit
import MesonSDK
import AdSupport

@main
class AppDelegate: UIResponder, UIApplicationDelegate {    

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.        

         #warning("Please  initialize APS SDK before meson SDK")
        initializeAPSSDK()

        initializeMesonSDK()
    }    

    func initializeAPSSDK() {
        #warning("Please initialize with APS AppKey" )
        APSBidLoader.initializeAmazonSDK(with: "<AppKey>")
    }

Objective-C

#import "AppDelegate.h"
@import MesonSDK;
#import <MesonIntegrationApp-Swift.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    #warning("Please  initialize APS SDK before meson SDK")
    [self initializeAPSSDK];
    [self initializeMesonSDK];        
    return YES;
}
- (void)initializeAPSSDK {
    #warning("Please initialize with APS AppKey" )
    [APSBidLoader initializeAmazonSDKWith:@"<AppKey>"];
}

Load Banner Ads from Amazon’s SDK

To integrate Amazon banner ads into Meson, load the Amazon ad and pass the DTBAdResponse or DTBAdErrorInfo into the instance of MesonBanner by calling self.banner?.headerBids = ["APS": value] before you load the MesonBanner ad.

INFO

  • The ‘mesonBannerHeaderBidsExpired’ delegate method should only be implemented if you are using a bidder (e.g., Amazon) to provide header bids for your MesonBanner. This delegate method facilitates updating Amazon bids during a MesonBanner refresh. Failure to implement this delegate method for bidders may result in your banner not displaying or displaying suboptimal ads.
  • Avoid calling the `load` method of the banner in the `mesonBannerHeaderBidsExpired` delegate method. Doing so can cause issues and lead to suboptimal ad serving. Instead, the delegate method should be used to fetch and update header bids, which will be automatically used in the next banner refresh cycle.

Swift

import Foundation
import MesonSDK

class APSBannerViewController: UIViewController {
    private var banner: MesonBanner!     

    #warning("Please enter you mesonBannerAdUnitId, apsBannerSlotId and requested adSize")
    let mesonBannerAdUnitId = <"meson_Banner_AdUnitId">
    let apsBannerSlotId = <"APS_Banner_SlotId">
    let requestedAdSize = CGSize(width: 320, height: 50)  

    override func viewDidLoad() {
        super.viewDidLoad()        

       loadBanner()
    }    

    func loadBanner() {
        /// Create an ad object
        banner = MesonBanner(adUnitId: mesonBannerAdUnitId, adSize: requestedAdSize, delegate: self)        

        /// Attach/Add the ad to the screen
        view.addSubview(banner)
        banner.center = view.center        

        /// Mark it as Hidden and show it on mesonBannerDidLoad
        banner.isHidden = true        

        /// Fetch the aps bid and set it in the headerBids
        APSBidLoader.loadBannerAd(with: apsBannerSlotId, adSize: requestedAdSize) { apsBidResponse in
            if let apsBidResponse = apsBidResponse {
                self.banner?.headerBids = ["APS": apsBidResponse]
            }
            /// Request for the ad
            self.banner?.load()
        }
    }
}

extension APSBannerViewController: MesonBannerDelegate {
    /// Notifies the delegate that the banner header bids have expired. Please fetch and update the new header bids.
    func mesonBannerHeaderBidsExpired(_ banner: MesonBanner) {
        #warning("Note that this delegate should only be implemented for bidders as it facilitates the updating of APS bids in the event of a MesonBanner refresh.")
        APSBidLoader.loadBannerAd(with: apsBannerSlotId, adSize: requestedAdSize) { apsBidResponse in
            if let apsBidResponse = apsBidResponse {
                self.banner?.headerBids = ["APS": apsBidResponse]
            }
        }
    }    

    /// Returns the view controller on the screen
    /// - Returns: view controller where banner will be displayed
    func viewControllerForMesonBannerFullScreen() -> UIViewController {
        self
    }    

    /// Notifies the delegate that the banner has finished loading
    func mesonBannerDidLoad(_ banner: MesonBanner) {
        print(#function)
        banner.isHidden = false
    }

    /// Notifies the delegate that the banner has failed to load with some error.
    func mesonBannerDidFailToLoad(_ banner: MesonBanner, error: Error) {
        print(#function, error.localizedDescription)
    }

    /// Notifies the delegate that the banner was clicked.
    func mesonBannerDidClick(_ banner: MesonBanner, params: [String : Any]?) {
        print(#function)
    }

    /// Notifies the delegate that the user would be taken out of the application.
    func mesonBannerUserWillLeaveApplication(_ banner: MesonBanner) {
        print(#function)
    }

    /// Notifies the delegate that the banner would be presenting a full screen content.
    func mesonBannerWillPresentScreen(_ banner: MesonBanner) {
        print(#function)
    }

    /// Notifies the delegate that the banner has finished presenting screen.
    func mesonBannerDidPresentScreen(_ banner: MesonBanner) {
        print(#function)
    }

    /// Notifies the delegate that the banner will start dismissing the presented screen.
    func mesonBannerWillCollapseScreen(_ banner: MesonBanner) {
        print(#function)
    }

    /// Notifies the delegate that the banner has dismissed the presented screen.
    func mesonBannerDidCollapseScreen(_ banner: MesonBanner) {
        print(#function)
    }

    /// Notifies the delegate that the banner has completed ad impression.
    func mesonBannerImpression(_ banner: MesonBanner, adData: MesonAdData?) {
        print(#function)
    }    
}

Objective-C


#import "APSBannerViewController.h"
@import MesonSDK;
#import <MesonIntegrationApp-Swift.h>

@interface APSBannerViewController () <MesonBannerDelegate>
@property(nonatomic, strong) MesonBanner *bannerAd;
@end

@implementation APSBannerViewController

#warning("Please enter you RequestedSize adSize and APSBannerSlotID")
static CGSize const RequestedSize = {320, 50};
static NSString* const APSBannerSlotID = <APS_Banner_SlotID>;


- (void)viewDidLoad {

    [super viewDidLoad];
    [self loadBanner];
}


-(void)loadBanner {    

    #warning("Please enter you adUnitId and requested adSize")
    /// Create an ad object
    self.bannerAd = [[MesonBanner alloc] initWithAdUnitId:<Meson_Banner_AdUnitID> adSize:RequestedSize delegate:self];    

    self.bannerAd.center = [self.view center];
    /// Attach/Add the ad to the screen
    [self.view addSubview:self.bannerAd];    

    /// Mark it as Hidden and show it on mesonBannerDidLoad
    [self.bannerAd setHidden:true];    

    /// Fetch the aps bid and set it in the headerBids
    [APSBidLoader loadBannerAdWith:APSBannerSlotID adSize:RequestedSize completionHandler:^(id _Nullable apsBidResponse) {
        if (apsBidResponse != nil) {
            self.bannerAd.headerBids = @{@"APS" : apsBidResponse};
        }       

        /// Request for the ad
        [self.bannerAd load];
    }];
}

#pragma mark - MesonBannerDelegate
/// Notifies the delegate that the banner header bids have expired. Please fetch and update the new header bids.
- (void)mesonBannerHeaderBidsExpired:(MesonBanner *)banner {
    #warning("Note that this delegate should only be implemented for bidders as it facilitates the updating of APS bids in the event of a MesonBanner refresh.")    

    /// Fetch the aps bid and set it in the headerBids
    [APSBidLoader loadBannerAdWith:APSBannerSlotID adSize:RequestedSize completionHandler:^(id _Nullable apsBidResponse) {
        if (apsBidResponse != nil) {
            self.bannerAd.headerBids = @{@"APS" : apsBidResponse};
        }
    }];
}

/// Returns the view controller on the screen
///
/// returns:
/// view controller where banner will be displayed
- (UIViewController *)viewControllerForMesonBannerFullScreen {
    return self;
}

/// Notifies the delegate that the banner has finished loading
- (void)mesonBannerDidLoad:(MesonBanner * _Nonnull)banner {
    NSLog(@"%@", NSStringFromSelector(_cmd));    
    [self.bannerAd setHidden:false];
}

/// Notifies the delegate that the banner has failed to load with some error.
- (void)mesonBannerDidFailToLoad:(MesonBanner * _Nonnull)banner error:(NSError * _Nonnull)error {
    NSLog(@"%@ %@", NSStringFromSelector(_cmd), error);
}

/// Notifies the delegate that the banner was clicked.
- (void)mesonBannerDidClick:(MesonBanner * _Nonnull)banner params:(NSDictionary<NSString *, id> * _Nullable)params {
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

/// Notifies the delegate that the user would be taken out of the application.
- (void)mesonBannerUserWillLeaveApplication:(MesonBanner * _Nonnull)banner {
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

/// Notifies the delegate that the banner would be presenting a full screen content.
- (void)mesonBannerWillPresentScreen:(MesonBanner * _Nonnull)banner {
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

/// Notifies the delegate that the banner has finished presenting screen.
- (void)mesonBannerDidPresentScreen:(MesonBanner * _Nonnull)banner {
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

/// Notifies the delegate that the banner will start dismissing the presented screen.
- (void)mesonBannerWillCollapseScreen:(MesonBanner * _Nonnull)banner {
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

/// Notifies the delegate that the banner has dismissed the presented screen.
- (void)mesonBannerDidCollapseScreen:(MesonBanner * _Nonnull)banner {
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

/// Notifies the delegate that the banner has completed ad impression.
- (void)mesonBannerImpression:(MesonBanner * _Nonnull)banner adData:(MesonAdData * _Nullable)adData {
    NSLog(@"%@", NSStringFromSelector(_cmd));
}
@end

Load Interstitial Ads from Amazon's SDK

To integrate Amazon's interstitial ads into Meson, load the Amazon ad and pass the DTBAdResponse or DTBAdErrorInfo into the instance of MesonInterstitial by calling self.interstitial?.headerBids = ["APS": value] before you load the Meson ad.

Swift


import Foundation
import MesonSDK

class APSInterstitialViewController: UIViewController {
    private var interstitial: MesonInterstitial!
    
    #warning("Please enter you mesonInterstitialAdUnitId and apsInterstitialSlotId")
    let mesonInterstitialAdUnitId = <"meson_Interstital_AdUnitId">
    let apsInterstitialSlotId = <"APS_Interstital_SlotId">
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
       loadInterstitial()
    }
    
    func loadInterstitial() {
        /// Create an ad object
        interstitial = MesonInterstitial(adUnitId: mesonInterstitialAdUnitId, delegate: self)
        
        /// Fetch the aps bid and set it in the headerBids
        APSBidLoader.loadInterstitialAd(with: apsInterstitialSlotId) { apsBidResponse in
            if let apsBidResponse = apsBidResponse {
                self.interstitial?.headerBids = ["APS": apsBidResponse]
            }
            /// Request for the ad
            self.interstitial.load()
        }
    }
}

extension APSInterstitialViewController: MesonInterstitialDelegate {
    /// Notifies the delegate that the interstitial has finished loading and can be shown instantly.
    func mesonInterstitialDidLoad(_ interstitial: MesonInterstitial) {
        print(#function)
        if self.interstitial.isReady {
            /// Show the Ad
            self.interstitial.show(from: self)
        }
    }

    /// Notifies the delegate that the interstitial has failed to load with some error.
    func mesonInterstitialDidFailToLoad(_ interstitial: MesonInterstitial, error: Error) {
        print(#function, error.localizedDescription)
    }

    /// Notifies the delegate that the interstitial has failed to be displayed with some error.
    func mesonInterstitialDidFailToDisplay(_ interstitial: MesonInterstitial, error: Error) {
        print(#function)
    }

    /// Notifies the delegate that the interstitial has been clicked.
    func mesonInterstitialDidClick(_ interstitial: MesonInterstitial, params: [String : Any]?) {
        print(#function)
    }

    /// Notifies the delegate that the user would be taken out of the application.
    func mesonInterstitialUserWillLeaveApplication(_ interstitial: MesonInterstitial) {
        print(#function)
    }

    /// Notifies the delegate that the interstitial would be displayed.
    func mesonInterstitialWillDisplay(_ interstitial: MesonInterstitial) {
        print(#function)
    }

    /// Notifies the delegate that the interstitial has been displayed.
    func mesonInterstitialDidDisplay(_ interstitial: MesonInterstitial) {
        print(#function)
    }

    /// Notifies the delegate that the interstitial will be dismissed.
    func mesonInterstitialWillDismiss(_ interstitial: MesonInterstitial) {
        print(#function)
    }

    /// Notifies the delegate that the interstitial has been dismissed.
    func mesonInterstitialDidDismiss(_ interstitial: MesonInterstitial) {
        print(#function)
    }

    /// Notifies the delegate that the interstitial has completed ad impression.
    func mesonInterstitialImpression(_ interstitial: MesonInterstitial, adData: MesonAdData?) {
        print(#function)
    }

    /// Notifies the delegate that the user has unlocked a reward for the action.
    func mesonRewardsUnlocked(_ interstitial: MesonInterstitial, rewards: [String : Any]) {
        print(#function)
    }
}

Objective-C


#import "APSInterstitialViewController.h"
@import MesonSDK;
#import <MesonIntegrationApp-Swift.h>

@interface APSInterstitialViewController () <MesonInterstitialDelegate>
@property(nonatomic, strong) MesonInterstitial *interstitial;
@end

@implementation APSInterstitialViewController

#warning("Please enter you APSInterstitialSlotID")
static NSString* const APSInterstitialSlotID = @"<APS_Interstitial_SlotID>";

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self loadInterstitial];
}

-(void)loadInterstitial{
    #warning("Please enter you adUnitId")
    /// Create an ad object
    self.interstitial = [[MesonInterstitial alloc] initWithAdUnitId:@"<Meson_Interstitial_AdUnitID>" delegate:self];
    
    /// Fetch the aps bid and set it in the headerBids
    [APSBidLoader loadInterstitialAdWith:APSInterstitialSlotID completionHandler:^(id _Nullable apsBidResponse) {
        if (apsBidResponse != nil) {
            self.interstitial.headerBids = @{@"APS" : apsBidResponse};
        }
        
        /// Request for the ad
        [self.interstitial load];
    }];
}

#pragma mark - MesonInterstitialDelegate

/// Notifies the delegate that the interstitial has finished loading and can be shown instantly.
- (void)mesonInterstitialDidLoad:(MesonInterstitial * _Nonnull)interstitial {
    NSLog(@"%@", NSStringFromSelector(_cmd));
    
    if ([self.interstitial isReady]) {
        /// Show the Ad
        [self.interstitial showFromViewController:self];
    }
}

/// Notifies the delegate that the interstitial has failed to load with some error.
- (void)mesonInterstitialDidFailToLoad:(MesonInterstitial * _Nonnull)interstitial error:(NSError * _Nonnull)error{
    NSLog(@"%@ %@", NSStringFromSelector(_cmd), error);
}

/// Notifies the delegate that the interstitial has failed to be displayed with some error.
- (void)mesonInterstitialDidFailToDisplay:(MesonInterstitial * _Nonnull)interstitial error:(NSError * _Nonnull)error {
    NSLog(@"%@ %@", NSStringFromSelector(_cmd), error);
}

/// Notifies the delegate that the interstitial has been clicked.
- (void)mesonInterstitialDidClick:(MesonInterstitial * _Nonnull)interstitial params:(NSDictionary<NSString *, id> * _Nullable)params{
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

/// Notifies the delegate that the user would be taken out of the application.
- (void)mesonInterstitialUserWillLeaveApplication:(MesonInterstitial * _Nonnull)interstitial{
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

/// Notifies the delegate that the interstitial would be displayed.
- (void)mesonInterstitialWillDisplay:(MesonInterstitial * _Nonnull)interstitial{
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

/// Notifies the delegate that the interstitial has been displayed.
- (void)mesonInterstitialDidDisplay:(MesonInterstitial * _Nonnull)interstitial{
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

/// Notifies the delegate that the interstitial will be dismissed.
- (void)mesonInterstitialWillDismiss:(MesonInterstitial * _Nonnull)interstitial{
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

/// Notifies the delegate that the interstitial has been dismissed.
- (void)mesonInterstitialDidDismiss:(MesonInterstitial * _Nonnull)interstitial{
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

/// Notifies the delegate that the interstitial has completed ad impression.
- (void)mesonInterstitialImpression:(MesonInterstitial * _Nonnull)interstitial adData:(MesonAdData * _Nullable)adData{
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

@end

Load Rewarded Ads from Amazon's SDK

To integrate Amazon's video ads into Meson, load the Amazon ad and pass the DTBAdResponse or DTBAdErrorInfo into the instance of MesonInterstitial by calling self.rewarded?.headerBids = ["APS": value] before you load the Meson ad.

Swift


import Foundation
import MesonSDK

class APSRewardedViewController: UIViewController {
    private var rewarded: MesonInterstitial!
    
    #warning("Please enter you mesonRewardedAdUnitId and apsRewardedSlotId")
    let mesonRewardedAdUnitId = <"meson_Rewarded_AdUnitId">
    let apsRewardedSlotId = <"APS_Rewarded_SlotId">
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        loadRewarded()
    }
    
    func loadRewarded() {
        /// Create an ad object
        rewarded = MesonInterstitial(adUnitId: mesonRewardedAdUnitId, delegate: self)
        /// Fetch the aps bid and set it in the headerBids
        APSBidLoader.loadRewardedAd(with: apsRewardedSlotId) { apsBidResponse in
            if let apsBidResponse = apsBidResponse {
                self.rewarded?.headerBids = ["APS": apsBidResponse]
            }
            /// Request for the ad
            self.rewarded.load()
        }
    }
}

extension APSRewardedViewController: MesonInterstitialDelegate {
    /// Notifies the delegate that the interstitial has finished loading and can be shown instantly.
    func mesonInterstitialDidLoad(_ interstitial: MesonInterstitial) {
        print(#function)
        if self.rewarded.isReady {
            /// Show the Ad
            self.rewarded.show(from: self)
        }
    }

    /// Notifies the delegate that the interstitial has failed to load with some error.
    func mesonInterstitialDidFailToLoad(_ interstitial: MesonInterstitial, error: Error) {
        print(#function, error.localizedDescription)
    }

    /// Notifies the delegate that the interstitial has failed to be displayed with some error.
    func mesonInterstitialDidFailToDisplay(_ interstitial: MesonInterstitial, error: Error) {
        print(#function)
    }

    /// Notifies the delegate that the interstitial has been clicked.
    func mesonInterstitialDidClick(_ interstitial: MesonInterstitial, params: [String : Any]?) {
        print(#function)
    }

    /// Notifies the delegate that the user would be taken out of the application.
    func mesonInterstitialUserWillLeaveApplication(_ interstitial: MesonInterstitial) {
        print(#function)
    }

    /// Notifies the delegate that the interstitial would be displayed.
    func mesonInterstitialWillDisplay(_ interstitial: MesonInterstitial) {
        print(#function)
    }

    /// Notifies the delegate that the interstitial has been displayed.
    func mesonInterstitialDidDisplay(_ interstitial: MesonInterstitial) {
        print(#function)
    }

    /// Notifies the delegate that the interstitial will be dismissed.
    func mesonInterstitialWillDismiss(_ interstitial: MesonInterstitial) {
        print(#function)
    }

    /// Notifies the delegate that the interstitial has been dismissed.
    func mesonInterstitialDidDismiss(_ interstitial: MesonInterstitial) {
        print(#function)
    }

    /// Notifies the delegate that the interstitial has completed ad impression.
    func mesonInterstitialImpression(_ interstitial: MesonInterstitial, adData: MesonAdData?) {
        print(#function)
    }

    /// Notifies the delegate that the user has unlocked a reward for the action.
    func mesonRewardsUnlocked(_ interstitial: MesonInterstitial, rewards: [String : Any]) {
        print(#function)
    }
}

Objective-C


#import "APSRewardedViewController.h"
@import MesonSDK;
#import <MesonIntegrationApp-Swift.h>

@interface APSRewardedViewController () <MesonInterstitialDelegate>
@property(nonatomic, strong) MesonInterstitial *rewarded;
@end

@implementation APSRewardedViewController

#warning("Please enter you APSRewardedSlotID")
static NSString* const APSRewardedSlotID = @"<APS_Rewarded_SlotID>";

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self loadRewarded];
}

-(void)loadRewarded {
    #warning("Please enter you adUnitId")
    /// Create an ad object
    self.rewarded = [[MesonInterstitial alloc] initWithAdUnitId:@"<Meson_AdUnit_Id>" delegate:self];
    
    /// Fetch the aps bid and set it in the headerBids
    [APSBidLoader loadRewardedAdWith:APSRewardedSlotID completionHandler:^(id _Nullable apsBidResponse) {
        if (apsBidResponse != nil) {
            self.rewarded.headerBids = @{@"APS" : apsBidResponse};
        }
        
        /// Request for the ad
        [self.rewarded load];
    }];
}

#pragma mark - MesonInterstitialDelegate
/// Notifies the delegate that the interstitial has finished loading and can be shown instantly.
- (void)mesonInterstitialDidLoad:(MesonInterstitial * _Nonnull)interstitial {
    NSLog(@"%@", NSStringFromSelector(_cmd));
    
    if ([self.rewarded isReady]) {
        /// Show the Ad
        [self.rewarded showFromViewController:self];
    }
}

/// Notifies the delegate that the interstitial has failed to load with some error.
- (void)mesonInterstitialDidFailToLoad:(MesonInterstitial * _Nonnull)interstitial error:(NSError * _Nonnull)error{
    NSLog(@"%@ %@", NSStringFromSelector(_cmd), error);
}

/// Notifies the delegate that the interstitial has failed to be displayed with some error.
- (void)mesonInterstitialDidFailToDisplay:(MesonInterstitial * _Nonnull)interstitial error:(NSError * _Nonnull)error {
    NSLog(@"%@ %@", NSStringFromSelector(_cmd), error);
}

/// Notifies the delegate that the interstitial has been clicked.
- (void)mesonInterstitialDidClick:(MesonInterstitial * _Nonnull)interstitial params:(NSDictionary<NSString *, id> * _Nullable)params{
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

/// Notifies the delegate that the user would be taken out of the application.
- (void)mesonInterstitialUserWillLeaveApplication:(MesonInterstitial * _Nonnull)interstitial{
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

/// Notifies the delegate that the interstitial would be displayed.
- (void)mesonInterstitialWillDisplay:(MesonInterstitial * _Nonnull)interstitial{
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

/// Notifies the delegate that the interstitial has been displayed.
- (void)mesonInterstitialDidDisplay:(MesonInterstitial * _Nonnull)interstitial{
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

/// Notifies the delegate that the interstitial will be dismissed.
- (void)mesonInterstitialWillDismiss:(MesonInterstitial * _Nonnull)interstitial{
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

/// Notifies the delegate that the interstitial has been dismissed.
- (void)mesonInterstitialDidDismiss:(MesonInterstitial * _Nonnull)interstitial{
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

/// Notifies the delegate that the interstitial has completed ad impression.
- (void)mesonInterstitialImpression:(MesonInterstitial * _Nonnull)interstitial adData:(MesonAdData * _Nullable)adData{
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

/// Notifies the delegate that the user has unlocked a reward for the action.
- (void)mesonRewardsUnlocked:(MesonInterstitial * _Nonnull)interstitial rewards:(NSDictionary<NSString *, id> * _Nonnull)rewards {
    NSLog(@"%@ %@", NSStringFromSelector(_cmd), rewards);
}

@end