iOS Banner Integration (V2)

Note:

The following is a document of the new and improved version of the MAS Banner API. Please follow this guide if you are integrating MAS in your game for the first time.

If you are an existing customer integrating a new game or updating an existing game, we strongly encourage you to use this guide, but you can access the documentation of the old banner API here.

1. Init Yodo1MasBannerAdView

For Objective-C

Yodo1MasBannerAdView *bannerAdView = [[Yodo1MasBannerAdView alloc] init];
[bannerAdView setAdSize:Yodo1MasBannerAdSizeBanner];
// TODO: Add bannerAdView to your view hierarchy.

For Swift

let bannerAdView = Yodo1MasBannerAdView()
bannerAdView.setAdSize(.banner)
// TODO: Add bannerAdView to your view hierarchy.

Note: If your game was live with MAS already, please contact your Customer Success Manager about using banners of another size than 320×50.

Size in dpDescriptionAvailabilityAdSize constant
320×50BannerPhones and TabletsBanner
320×100Large BannerPhones and TabletsLargeBanner
300×250IAB Medium RectanglePhones and TabletsIABMediumRectangle
Full screen width x Adaptive heightAdaptive bannerPhones and TabletsAdaptiveBanner
Screen width x 32/50/90Smart bannerPhones and TabletsSmartBanner

2. Load an ad

Once the Yodo1MasBannerAdView is in place, the next step is to load an ad. That’s done with the loadAd() method in the Yodo1MasBannerAdView class.

Here’s an example that shows how to load an ad in the viewDidLoad method of an UIViewController:

For Objective-C

#import <UIKit/UIKit.h>
#import "Yodo1Mas.h"
#import "Yodo1MasBannerAdView.h"
  
@interface MainController ()
  
@property (nonatomic, strong) Yodo1MasBannerAdView *bannerAdView;

@end

@implementation BannerController
  
- (void)viewDidLoad {
  [super viewDidLoad];
  [[Yodo1Mas sharedInstance] initWithAppKey:@"YourAppKey" successful:^{

  } fail:^(NSError * _Nonnull error) {

  }];
  
  _bannerAdView = [[Yodo1MasBannerAdView alloc] init];
  [_bannerAdView setAdSize:Yodo1MasBannerAdSizeBanner];
  [_bannerAdView loadAd];
	CGSize size = _bannerAdView.intrinsicContentSize;
  _bannerAdView.frame = CGRectMake((self.view.bounds.size.width - size.width) / 2, self.view.bounds.size.height - size.height, size.width, size.height);
  [self.view addSubview:_bannerAdView];
}
@end

For Swift

import UIKit
import Yodo1MasCore

class MainController : UIViewController {

	var bannerAdView: Yodo1MasBannerAdView!

	override func viewDidLoad() {
		super.viewDidLoad()
    Yodo1Mas.sharedInstance().initWithAppKey("YourAppKey") {
            
    } fail: { error in

    }
    bannerAdView = Yodo1MasBannerAdView()
    bannerAdView.setAdSize(.banner)
    bannerAdView.loadAd()
    let size = bannerAdView.intrinsicContentSize
    bannerAdView.frame = CGRect(x: (self.view.bounds.width - size.width) / 2, y: self.view.bounds.height - size.height, width: size.width, height: size.height)
    self.view.addSubview(bannerAdView)
   }
}

That’s it! Your app is now ready to display banner ads.

3. Ad events

To further customize the behavior of your ad, you can hook onto a number of events in the ad’s lifecycle: loading, opening, closing, and so on. You can listen for these events through the Yodo1MasBannerAdListener class.

For Objective-C

#import <UIKit/UIKit.h>
#import "Yodo1Mas.h"
#import "Yodo1MasBannerAdView.h"
  
@interface MainController ()<Yodo1MasBannerAdViewDelegate>
  
@property (nonatomic, strong) Yodo1MasBannerAdView *bannerAdView;

@end

@implementation BannerController
  
- (void)viewDidLoad {
  [super viewDidLoad];
  [[Yodo1Mas sharedInstance] initWithAppKey:@"YourAppKey" successful:^{

  } fail:^(NSError * _Nonnull error) {

  }];
  
  _bannerAdView = [[Yodo1MasBannerAdView alloc] init];
  [_bannerAdView setAdSize:Yodo1MasBannerAdSizeBanner];
  [_bannerAdView loadAd];
	CGSize size = _bannerAdView.intrinsicContentSize;
  _bannerAdView.frame = CGRectMake((self.view.bounds.size.width - size.width) / 2, self.view.bounds.size.height - size.height, size.width, size.height);
  [self.view addSubview:_bannerAdView];
}


#pragma mark - Yodo1MasBannerAdViewDelegate
- (void)onBannerAdLoaded:(Yodo1MasBannerAdView *)banner {
    
}

- (void)onBannerAdFailedToLoad:(Yodo1MasBannerAdView *)banner withError:(Yodo1MasError *)error {
    
}

- (void)onBannerAdOpened:(Yodo1MasBannerAdView *)banner {

}

- (void)onBannerAdFailedToOpen:(Yodo1MasBannerAdView *)banner withError:(Yodo1MasError *)error {
    
}

- (void)onBannerAdClosed:(Yodo1MasBannerAdView *)banner {

}

@end

For Swift

import UIKit
import Yodo1MasCore

class MainController: UIViewController {
    var bannerAdView: Yodo1MasBannerAdView!

    override func viewDidLoad() {
        super.viewDidLoad()
        
        Yodo1Mas.sharedInstance().initWithAppKey("YourAppKey") {
            
        } fail: { error in
            
        }
        
        bannerAdView = Yodo1MasBannerAdView()
        bannerAdView.setAdSize(.banner)
        bannerAdView.adDelegate = self
        bannerAdView.loadAd()
        let size = bannerAdView.intrinsicContentSize
        bannerAdView.frame = CGRect(x: (self.view.bounds.width - size.width) / 2, y: self.view.bounds.height - size.height, width: size.width, height: size.height)
        self.view.addSubview(bannerAdView)
    }
}

extension MainController: Yodo1MasBannerAdViewDelegate {
    // MARK: Yodo1MasBannerAdViewDelegate
    func onBannerAdLoaded(_ banner: Yodo1MasBannerAdView) {
        
    }
    
    func onBannerAdFailed(toLoad banner: Yodo1MasBannerAdView, withError error: Yodo1MasError) {
        
    }
    
    func onBannerAdOpened(_ banner: Yodo1MasBannerAdView) {
        
    }
    
    func onBannerAdFailed(toOpen banner: Yodo1MasBannerAdView, withError error: Yodo1MasError) {
        
    }
    
    func onBannerAdClosed(_ banner: Yodo1MasBannerAdView) {
        
    }
    
}
Updated on November 18, 2021

Was this article helpful?

Related Articles