Back to top

Banner Ad Units

Last Updated on: 12 Jul, 2022

Create Banner Ad Unit

INFO

If you miss to Initialize the SDK, this method will fail to return a response.

To create a new banner ad, create a MesonBanner object.

Swift

var bannerAd: MesonBanner = MesonBanner.init(adUnitId: "AD_UNIT_ID", adSize: "<CGSize>", delegate: self)

Objective-C

MesonBanner *bannerAd = [[MesonBanner alloc] initWithAdUnitId:@"AD_UNIT_ID" adSize:CGSize delegate:self];

Set Banner Animation

Additional APIs to control the transition of the banner ads.

Swift

bannerAd.animationTransition = .flipFromLeft

Objective-C

bannerAd.animationTransition = UIViewAnimationTransitionFlipFromLeft;

Register for Postbacks

Track the ad lifecycle for banner ads. All the available events for banner ads are listed below.

Swift

extension <#Class> : MesonBannerDelegate {

  func viewControllerForMesonBannerFullScreen() -> UIViewController? {
  return <UIViewController>
  }
  
  func mesonBannerDidLoad(_ bannerAd: MesonBanner) {
  }
  
  func mesonBannerDidFailToLoad(_ bannerAd: MesonBanner, error: Error?) {
  }
  
  func mesonBannerImpression(_ bannerAd: MesonBanner, adData: MesonAdData?) {
  }
  
  func mesonBannerDidPresentScreen(_ bannerAd: MesonBanner) {
  }
  
  func mesonBannerDidCollapseScreen(_ bannerAd: MesonBanner) {
  }
  
  func mesonBannerWillPresentScreen(_ bannerAd: MesonBanner) {
  }
  
  func mesonBannerWillCollapseScreen(_ bannerAd: MesonBanner) {
  }
  
  func mesonBannerDidClick(_ banner: MesonBanner, params: [String : Any]?) {
  }
  
  func mesonBannerUserWillLeaveApplication(_ bannerAd: MesonBanner) {
  }
}

Objective-C

- (UIViewController *)viewControllerForMesonBannerFullScreen {
  return <UIViewController>;
}

- (void)mesonBannerDidLoad:(MesonBanner *)bannerAd {
}

- (void)mesonBannerDidFailToLoad:(MesonBanner *)bannerAd error:(NSError *)error {
}

- (void)mesonBannerImpression:(MesonBanner *)bannerAd adData:(MesonAdData *)adData{
}

- (void)mesonBannerDidClick:(MesonBanner *)banner params:(NSDictionary<NSString *,id> *)params {
}

- (void)mesonBannerUserWillLeaveApplication:(MesonBanner *)bannerAd {
}

- (void)mesonBannerWillPresentScreen:(MesonBanner *)bannerAd {
}

- (void)mesonBannerDidPresentScreen:(MesonBanner *)bannerAd {
}

- (void)mesonBannerWillCollapseScreen:(MesonBanner *)bannerAd {
}

- (void)mesonBannerDidCollapseScreen:(MesonBanner *)bannerAd {
}

Load and Show

The publisher can request a banner ad by invoking this method. This will request an ad from all demand sources, select a winner, and once the ad is available show the ad to the end-user.

Swift

bannerAd.load() 
self.view.addSubview(bannerAd)

Objective-C

[bannerAd load]; 
[self.view addSubview:bannerAd];