Banner

Last Updated on: 19 Sep, 2023

Create Banner Ad

INFO

If you miss to Initialize the SDK, this method will fail to return a response. The MesonBanner is simply a UIView subclass displaying ads.

To create a new banner ad, create MesonBanner object using your adUnitId and call load method to make an ad request. This will request an ad from all demand sources, select a winner, and show the ad to the end user once the ad is available.

Parameters Data Type Info
adUnitId String

Present on Meson UI by creating an ad unit under an app. An ad unit id is a unique identifier.

For more information on how to set up an ad unit, see Set up Ad Units.

adSize CGSize (320,50)

Swift

import Foundation
import MesonSDK

class BannerViewController: UIViewController {
    private var banner: MesonBanner!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        #warning("Please enter you adUnitId and requested adSize")
        /// Create an ad object
        let requestedAdSize = CGSize(width: 320, height: 50)
        banner = MesonBanner(adUnitId: "<Your ad unit id>", adSize: requestedAdSize, delegate: self)
        /// Request for the ad
        banner.load()
        
        /// Attach/Add the ad to the screen
        view.addSubview(banner)
        
        /// Mark it as Hidden and show it on mesonBannerDidLoad
        banner.isHidden = true
    }
}

Objective-C

#import "BannerViewController.h"
@import MesonSDK;

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

@implementation BannerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    #warning("Please enter you adUnitId and requested adSize")
    /// Create an ad object
    CGSize requestedAdSize = CGSizeMake(320, 50);
    self.bannerAd = [[MesonBanner alloc] initWithAdUnitId:@"<Your ad unit id>" adSize:requestedAdSize delegate:self];
    /// Request for the ad
    [self.bannerAd load];
    
    /// 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];
} 

Delegates

Implement MesonBannerDelegate to get ad-related events.

Swift

extension BannerViewController: MesonBannerDelegate {
    /// 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

#pragma mark - MesonBannerDelegate

/// 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 

Refresh

You can set the Banner Refresh time on the Meson UI. To Set Banner Refresh, follow the instructions below:

  1. Go to Ad Experience. For more information, see Manage Ad Experience.
  2. Select the Banner ad template to which the banner belongs.
  3. Select Refresh time from the drop-down menu.

Banner Animation Types

You can set the following transitions while refreshing your banner object:

Swift

  • none
  • flipFromLeft
  • flipFromRight
  • curlUp
  • curlDown

Objective-C

  • UIViewAnimationTransitionNone 
  • UIViewAnimationTransitionFlipFromLeft 
  • UIViewAnimationTransitionFlipFromRight 
  • UIViewAnimationTransitionCurlUp
  • UIViewAnimationTransitionCurlDown 

Set Banner Animation

Additional APIs to control the transition of the banner ads.

Swift

banner.animationTransition = .flipFromLeft

Objective-C

self.bannerAd.animationTransition = UIViewAnimationTransitionFlipFromLeft;