Skip to main content

Banners

This page is describes how to implement banner ads though the Bidon SDK.

Loading an Banners

To load banner, create a BDNBanner. Implement BDNAdViewDelegate that you are notified when your ad is ready and of other ad-related events. This argument can be ad revenue value from mediaton.

caution

Set rootViewController property before attemp to call loadAd method!

class ViewController: UIViewController {
var banner: Bidon.Banner!

func loadBanner() {
banner = Bidon.Banner(frame: .zero)
banner.rootViewController = self
banner.format = .banner
banner.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(banner)
NSLayoutConstraint.activate([
banner.heightAnchor.constraint(equalToConstant: 50),
banner.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
banner.leftAnchor.constraint(equalTo: view.leftAnchor),
banner.rightAnchor.constraint(equalTo: view.rightAnchor)
])

banner.loadAd(with: 0.1)
}
}


extension ViewController: Bidon.AdViewDelegate {
func adView(_ adView: UIView & Bidon.AdView, willPresentScreen ad: Bidon.Ad) {}

func adView(_ adView: UIView & Bidon.AdView, didDismissScreen ad: Bidon.Ad) {}

func adView(_ adView: UIView & Bidon.AdView, willLeaveApplication ad: Bidon.Ad) {}

func adObject(_ adObject: Bidon.AdObject, didLoadAd ad: Bidon.Ad) {}

func adObject(_ adObject: Bidon.AdObject, didFailToLoadAd error: Error) {}
}

Ad View Format

Ad View FormatSizeDescription
banner320 x 50Fixed size banner for phones
leaderboard728 x 90Fixed size banner for pads
mrec300 x 250Fixed medium rectangle banners
adaptive-/- x 50/90Flexible width banners

The BannerProvider class offers methods for integrating banner advertisements into your application. It's main function to display banner ads at the fixed or custom position at the screen without complex layout logic. This documentation will walk you through the integration process and explain the available functions.

Creating instance

Create an instance of the BannerProvider class and use its methods to load and display banner ads. You can specify format of wanted banner ad, delegate of banner and root view controller. Where format is member of BannerFormat enum.

info

By default BannerProvider will use banner format for loading and displaying ads. The topmost application controller is presented as rootViewController.


final class ViewController: UIViewController {
lazy var provider: BannerProvider = {
let provider = BannerProvider()
provider.format = .banner
provider.rootViewController = self
provider.delegate = self
return provider
}()
}

Positioning

Before showing an banner ad you can set fixed or custom position at the screen. By default, banner will be displayed at the bottom of the screen.

Fixed position


final class ViewController: UIViewController {
lazy var provider: BannerProvider = {
provider.format = .banner
provider.rootViewController = self
provider.delegate = self
provider.setFixedPosition(.horizontalBottom)
return provider
}()
}

The BannerPosition enum represents different positions where banner advertisements can be displayed within a screen. It offers four possible banner positions, each serving a unique purpose:

PositionDescription
horizontalBottomThis position places the banner at the bottom of the screen, typically spanning horizontally
horizontalTopThis position places the banner at the top of the screen, typically spanning horizontally
verticalLeftThis position places the banner on the left side of the screen, typically spanning vertically
verticalRightThis position places the banner on the right side of the screen, typically spanning vertically

Custom position

Set a custom position for the banner. You can specify the top-left offset in points, rotation in degrees, and the anchor point in relative coordinates (0 to 1, starting from the top-left corner).


final class ViewController: UIViewController {
lazy var provider: BannerProvider = {
provider.format = .banner
provider.rootViewController = self
provider.delegate = self
provider.setCustomPosition(
CGPoint(x: 25, y: UIScreen.main.bounds.height / 2),
rotationAngleDegrees: 90,
anchorPoint: CGPoint(x: 0.5, y: 0.5)
)
return provider
}()
}

Loading

Load the banner ad. You should provide the current root view controller where the ad will be displayed. Optionally, you can specify a price floor for the ad. Also you can call load method when another ad was displayed it will refresh the ad after loading.


final class ViewController: UIViewController {
func loadBanner() {
provider.loadAd(with: 0.1)
}
}

Check if the banner provider has ready ad to be shown.


provider.isReady

Displaying

Show the banner ad

info

In case of banner is in loading at the show moment it will add empty transparent container on root view controller view and will show banner after loading in it.


func showBanner() {
provider.show()
}

Check if the banner provider has been shown.


provider.isShowing

Hiding

Hide the banner ad.


func hideBanner() {
provider.hide()
}

Callbacks

BannerProvider has delegate property of AdObjectDelegate type. You can implement this interface to be notified about banner events.


extension ViewController: AdObjectDelegate {
func adObjectDidReceiveAd(_ adObject: AdObject) {}

func adObject(_ adObject: AdObject, didFailToLoadAd error: Error) {}
}