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.
Set rootViewController
property before attemp to call loadAd method!
- Swift
- Objective-C
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) {}
}
#import "ViewController.h"
#import <AppLovinSDK/AppLovinSDK.h>
#import <Bidon/Bidon-Swift.h>
@interface ViewController() <BDNAdViewDelegate>
@property (nonatomic, strong) BDNBannerView *banner;
@end
@implementation ViewController
- (void)createBanner {
self.banner = [[BDNBannerView alloc] initWithFrame:CGRectZero placement:@"default"];
self.banner.format = BDNBannerFormatBanner;
self.banner.delegate = self;
self.banner.translatesAutoresizingMaskIntoConstraints = NO;
[self.banner loadAdWith:0.1];
[self.view addSubview: self.banner];
[NSLayoutConstraint activateConstraints:@[
[self.banner.heightAnchor constraintEqualToConstant:50],
[self.banner.bottomAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor],
[self.banner.leftAnchor constraintEqualToAnchor:self.view.leftAnchor],
[self.banner.rightAnchor constraintEqualToAnchor:self.view.rightAnchor]
]];
[self.banner loadAdWith:0.1];
}
#pragma mark - BDNAdViewDelegate Protocol
- (void)adObject:(id<BDNAdObject>)adObject didFailToLoadAd:(NSError *)error {}
- (void)adObject:(id<BDNAdObject>)adObject didLoadAd:(id<BDNAd>)ad {}
- (void)adView:(UIView<BDNAdView> *)adView didDismissScreen:(id<BDNAd>)ad {}
- (void)adView:(UIView<BDNAdView> *)adView willLeaveApplication:(id<BDNAd>)ad {}
- (void)adView:(UIView<BDNAdView> *)adView willPresentScreen:(id<BDNAd>)ad {}
@end
Ad View Format
Ad View Format | Size | Description |
---|---|---|
banner | 320 x 50 | Fixed size banner for phones |
leaderboard | 728 x 90 | Fixed size banner for pads |
mrec | 300 x 250 | Fixed medium rectangle banners |
adaptive | -/- x 50/90 | Flexible width banners |
Banner Provider
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.
By default BannerProvider
will use banner
format for loading and displaying ads.
The topmost application controller is presented as rootViewController
.
- Swift
- Objective-C
final class ViewController: UIViewController {
lazy var provider: BannerProvider = {
let provider = BannerProvider()
provider.format = .banner
provider.rootViewController = self
provider.delegate = self
return provider
}()
}
@interface ViewController ()
@property (nonatomic, strong) BDNBannerProvider *provider;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.provider = [[BDNBannerProvider alloc] init];
self.provider.format = BDNBannerFormatBanner;
self.provider.rootViewController = self;
self.provider.delegate = self;
}
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
- Swift
- Objective-C
final class ViewController: UIViewController {
lazy var provider: BannerProvider = {
provider.format = .banner
provider.rootViewController = self
provider.delegate = self
provider.setFixedPosition(.horizontalBottom)
return provider
}()
}
@interface ViewController ()
@property (nonatomic, strong) BDNBannerProvider *provider;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.provider = [[BDNBannerProvider alloc] init];
self.provider.format = BDNBannerFormatBanner;
self.provider.rootViewController = self;
self.provider.delegate = self;
[self.provider setFixedPosition:BDNBannerPositionHorizontalBottom];
}
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:
Position | Description |
---|---|
horizontalBottom | This position places the banner at the bottom of the screen, typically spanning horizontally |
horizontalTop | This position places the banner at the top of the screen, typically spanning horizontally |
verticalLeft | This position places the banner on the left side of the screen, typically spanning vertically |
verticalRight | This 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).
- Swift
- Objective-C
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
}()
}
@interface ViewController ()
@property (nonatomic, strong) BDNBannerProvider *provider;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.provider = [[BDNBannerProvider alloc] init];
self.provider.format = BDNBannerFormatBanner;
self.provider.rootViewController = self;
self.provider.delegate = self;
[self.provider setCustomPosition:CGPointMake(25, UIScreen.mainScreen.bounds.size.height / 2)
rotationAngleDegrees:90
anchorPoint:CGPointMake(0.5, 0.5)];
}
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.
- Swift
- Objective-C
final class ViewController: UIViewController {
func loadBanner() {
provider.loadAd(with: 0.1)
}
}
@interface ViewController ()
@property (nonatomic, strong) BDNBannerProvider *provider;
@end
@implementation ViewController
- (void)loadBanner {
[self.provider loadAdWith:0.1];
}
Check if the banner provider has ready ad to be shown.
- Swift
- Objective-C
provider.isReady
[self.provider isReady];
Displaying
Show the banner ad
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.
- Swift
- Objective-C
func showBanner() {
provider.show()
}
- (void)showBanner {
[self.provider show];
}
Check if the banner provider has been shown.
- Swift
- Objective-C
provider.isShowing
[self.provider isShowing];
Hiding
Hide the banner ad.
- Swift
- Objective-C
func hideBanner() {
provider.hide()
}
- (void)hideBanner {
[self.provider hide];
}
Callbacks
BannerProvider
has delegate property of AdObjectDelegate
type. You can implement this interface to be notified about banner events.
- Swift
- Objective-C
extension ViewController: AdObjectDelegate {
func adObjectDidReceiveAd(_ adObject: AdObject) {}
func adObject(_ adObject: AdObject, didFailToLoadAd error: Error) {}
}
#pragma mark - BDNAdObjectDelegate Protocol
- (void)adObject:(id<BDNAdObject>)adObject didFailToLoadAd:(NSError *)error {}
- (void)adObject:(id<BDNAdObject>)adObject didLoadAd:(id<BDNAd>)ad {}