Skip to content

Banner

An ADvantage banner is a NSObject that displays HTML5 ads that respond to user interaction (touch, wipe, click and etc.).

To add a banner to your view it takes only a few lines of code:

  • Create an new instance of ADvantage instance in your code (pass your license key, siteId and position to its constructor)
Swift
var banner: ADvantage?
.
.
.
banner = ADvantage(bannerWithLicenseKey: "...", siteId: "...", position: "...")
Objective-c
ADvantage *banner = [[ADvantage alloc] initBannerWithLicenseKey:@"..." SiteId:@"..." Position:@"..."];

Tip

We recommend to initialize ADvantage after your app have gone through it own initialization.

  • Add the ADvantage instance to your content view
Swift
container.addSubview(banner.view)
Objective-c
//Add ADvantage view to your layout
[container addSubview:banner.view];

Tip

To avoid the screen to be cropped you can use auto-layout constraints to contain your banner inside the view of your choosing.

  • Implement the delegation methods to be able to treat the different events from ADvantage (For more information please visit ADvantage events):
Swift
override func viewDidLoad() {
    ...
    banner.delegate = self
}

// Important methods for the ADvantage lifecycle
func advantage(_ advantage: ADvantage, didLoad state: AVLoadedState) {
    //Do something based on banner state
}

func advantage(_ advantage: ADvantage, didFailWithError error: String?)
    //Do someting after it fails
}
Objective-c
- (void)viewDidLoad{
    ...
    [banner setDelegate:controller];
}

// Important methods for the ADvantage lifecycle
- (void)advantage:(ADvantage *)advantage didLoad:(AVLoadedState)state {
    //Do something based on banner state
}

- (void)advantage:(ADvantage *)advantage didFailWithError:(NSString *)error {
    //Do someting after it fails
}
  • Load and show the ad via your ADvantage instances requestAd() method.
Swift
banner.requestAd()
Objective-c
//Show banner...
[banner requestAd];

Tip

It is common practice to create those objects inside a UIViewController viewDidLoad method.