Default Loading

BidMachine SDK supports several banner ad sizes:

Size

Description

320x50

iPhone in line banner

728x90

iPad in line banner

300x250

Medium Rectangle banner

You can set ad size to BDMBannerRequest object. By default, banner will try to get ad of 320x50 size for iPhone and 728x90 for iPad. Banner frame size does not equal ad size!

Banner ads are provided by BDMBannerView. BDMBannerView instances work with BDMBannerRequest. You can add banner to view hierarchy at any moment of its lifecycle, but check that banner always has a reference to the correct view controller!. If you want to pass banner view between several view controllers, you should pass the actual view controller instance to banner view anytime. If in some cases banner view doesn't have a direct reference to view controller, it brings the top presented view controller in the app.

Banner supports XCode interface builder system. You can add it to controller and associate view controller in storyboard on NIB file.

You can pass request to banner view using the following method: -populateWithRequest:.
Banner will create all objects to render a creative such as WKWebView only when the request returns callback on success and -populateWithRequest: is called.

You can also handle banner events. In this case, some of your classes should implement BDMBannerViewDelegate protocol.

import UIKit
import BidMachine

class BannerController: UIViewController {
    
    private var banner: BDMBannerView?
    
    func load() {
        let banner = BDMBannerView(frame: CGRect(origin: .zero, size: CGSizeFromBDMSize(.size320x50)))
        let request = BDMBannerRequest()
        
        banner.delegate = self
        banner.populate(with: request)
        
        self.banner = banner
    }
    
    func present() {
        guard let banner = self.banner, banner.canShow else {
            return
        }
        
        self.view.addSubview(banner)
    }
}

extension BannerController: BDMBannerDelegate {
    
    func bannerViewReady(toPresent bannerView: BDMBannerView) {
        
    }
    
    func bannerView(_ bannerView: BDMBannerView, failedWithError error: Error) {
        
    }
    
    func bannerViewRecieveUserInteraction(_ bannerView: BDMBannerView) {
        
    }
}
#import "BannerController.h"
#import <BidMachine/BidMachine.h>

@interface BannerController ()<BDMBannerDelegate>

@property (nonatomic, strong) BDMBannerView *banner;

@end

@implementation BannerController

- (void)load {
    
    BDMBannerRequest *request = [BDMBannerRequest new];
    BDMBannerView *banner = [[BDMBannerView alloc] initWithFrame:(CGRect){.size = CGSizeFromBDMSize(BDMBannerAdSize320x50)}];
    
    banner.delegate = self;
    [banner populateWithRequest:request];
    
    self.banner = banner;
}

- (void)show {
    if ([self.banner canShow]) {
        [self.view addSubview:self.banner];
    }
}

#pragma mark - BDMBannerDelegate

- (void)bannerViewReadyToPresent:(nonnull BDMBannerView *)bannerView {
    
}

- (void)bannerView:(nonnull BDMBannerView *)bannerView failedWithError:(nonnull NSError *)error {
    
}

- (void)bannerViewRecieveUserInteraction:(nonnull BDMBannerView *)bannerView {
    
}

@end

Advanced Loading

You can create BDMBannerRequest and perform a request by calling the -performWithDelegate: method. Delegate can be nil. When you receive callback on auction success, you can create (also you can defer with action) BDMBannerView instance and it should prepare creative for rendering.

🚧

Warning

Avoid multiple calling of -populateWithRequest: method on banner object. If you want to refresh the creative, the best practice is just to create a new banner instance.

import UIKit
import BidMachine

class AdvancedBannerController: UIViewController {
    
    private var banner: BDMBannerView?
    private var request: BDMBannerRequest?
    
    func load() {
        let request = BDMBannerRequest()
        request.perform(with: self)
        
        self.request = request
    }
    
    func present() {
        guard let banner = self.banner, banner.canShow else {
            return
        }
        
        self.view.addSubview(banner)
    }

}

extension AdvancedBannerController: BDMRequestDelegate {
    
    func requestDidExpire(_ request: BDMRequest) {
        
    }
    
    func request(_ request: BDMRequest, failedWithError error: Error) {
        
    }
    
    func request(_ request: BDMRequest, completeWith info: BDMAuctionInfo) {
        guard
            let request = request as? BDMBannerRequest
        else { return }
        
        let banner = BDMBannerView(frame: CGRect(origin: .zero, size: CGSizeFromBDMSize(.size320x50)))
        banner.delegate = self
        banner.populate(with: request)
        
        self.banner = banner
    }
}

extension AdvancedBannerController: BDMBannerDelegate {
    
    func bannerViewReady(toPresent bannerView: BDMBannerView) {
        
    }
    
    func bannerView(_ bannerView: BDMBannerView, failedWithError error: Error) {
        
    }
    
    func bannerViewRecieveUserInteraction(_ bannerView: BDMBannerView) {
        
    }
}
#import "AdvancedBannerController.h"
#import <BidMachine/BidMachine.h>

@interface AdvancedBannerController ()<BDMRequestDelegate, BDMBannerDelegate>

@property (nonatomic, strong) BDMBannerView *banner;
@property (nonatomic, strong) BDMBannerRequest *request;

@end

@implementation AdvancedBannerController

- (void)load {
    BDMBannerRequest *request = [BDMBannerRequest new];
    [request performWithDelegate:self];
    
    self.request = request;
}

- (void)show {
    if ([self.banner canShow]) {
        [self.view addSubview:self.banner];
    }
}

#pragma mark - BDMRequestDelegate

- (void)request:(nonnull BDMRequest *)request failedWithError:(nonnull NSError *)error {
    
}

- (void)request:(nonnull BDMRequest *)request completeWithInfo:(nonnull BDMAuctionInfo *)info {
    if (![request isKindOfClass:BDMInterstitialRequest.class]) {
        return;
    }
    
    self.banner = [[BDMBannerView alloc] initWithFrame:(CGRect){.size = CGSizeFromBDMSize(BDMBannerAdSize320x50)}];
    self.banner.delegate = self;
    [self.banner populateWithRequest:(BDMBannerRequest *)request];
}

- (void)requestDidExpire:(nonnull BDMRequest *)request {
    
}

#pragma mark - BDMBannerDelegate

- (void)bannerViewReadyToPresent:(nonnull BDMBannerView *)bannerView {
    
}

- (void)bannerView:(nonnull BDMBannerView *)bannerView failedWithError:(nonnull NSError *)error {
    
}

- (void)bannerViewRecieveUserInteraction:(nonnull BDMBannerView *)bannerView {
    
}

@end

Delegated Methods

BDMRequestDelegate

extension YourViewController: BDMRequestDelegate {
    func request(_ request: BDMRequest, failedWithError error: Error) {
      /// Called in case auction was unsuccessful or some error
      /// occurs due to auction
    }
     
    func request(_ request: BDMRequest, completeWith info: BDMAuctionInfo) {
      /// Called when auction is successfully finished. BDMAuctionInfo is object
      /// that contains info about win bid
      /// You can populate ad object in this method, to make ad object prepare creative
    }
     
    func requestDidExpire(_ request: BDMRequest) {
      /// Called in case if loaded ad was expired
    }
}
#pragma mark - BDMRequestDelegate
 
- (void)request:(BDMRequest *)request failedWithError:(NSError *)error {
  /// Called in case auction was unsuccessful or some error
  /// occurs due to auction
}
     
- (void)request:(BDMRequest *)request completeWithInfo:(BDMAuctionInfo *)info {
  /// Called when auction is successfully finished. BDMAuctionInfo is object
  /// that contains info about win bid
  /// You can populate ad object in this method, to make ad object prepare creative
}
 
- (void)requestDidExpire:(BDMRequest *)request {
  /// Called in case if loaded ad was expired
}

BDMBannerDelegate

extension BannerVC: BDMBannerDelegate {
    func bannerViewReady(toPresent bannerView: BDMBannerView) {
        /// Called in case banner ready to present to prepare
        /// creative
    }
     
    func bannerViewRecieveUserInteraction(_ bannerView: BDMBannerView) {
        /// Called when banner handle touch event. After this callback BidMachine try to
        /// open product link in StoreKit, Safari view controller or
        /// external browser
    }
 
    func bannerView(_ bannerView: BDMBannerView, failedWithError error: Error) {
        /// Called in case banner failed to prepare 
        /// creative
    }
}
#pragma mark - BDMBannerDelegate
 
- (void)bannerView:(BDMBannerView *)bannerView failedWithError:(NSError *)error {
    /// Called in case banner failed to prepare 
    /// creative
}
 
- (void)bannerViewReadyToPresentAd:(BDMBannerView *)bannerView {
    /// Called in case banner ready to present to prepare
    /// creative
}
 
- (void)bannerViewRecieveUserInteraction:(BDMBannerView *)bannerView {
    /// Called when banner handle touch event. After this callback BidMachine try to
    /// open product link in StoreKit, Safari view controller or
    /// external browser
}

BDMAdEventProducerDelegate

extension BannerVC {

     func updateDelegate() {

         self.banner.producerDelegate = self
     }
}

extension BannerVC: BDMAdEventProducerDelegate {

     func didProduceImpression(_ producer: BDMAdEventProducer) {
        /// Called when impression event was triggered
        /// Called 1 time per ad
    }
    
    func didProduceUserAction(_ producer: BDMAdEventProducer) {
        /// Called when click event was triggered
        /// Called 1 time per ad
    }
}
#pragma mark - BDMAdEventProducerDelegate

self.banner.producerDelegate = self

- (void)didProduceImpression:(nonnull id<BDMAdEventProducer>)producer {
    /// Called when impression event was triggered
    /// Called 1 time per ad
}

- (void)didProduceUserAction:(nonnull id<BDMAdEventProducer>)producer {
    /// Called when click event was triggered
    /// Called 1 time per ad
}