Interstitial

Default Loading

Interstitial ads support both MRAID and VAST ad formats. BDMInterstitial works this BDMInterstitialRequest. You can configure interstitial format by setting the type for BDMInterstitialRequest.

You can call -populateWithRequest: method with interstitial request object as an argument.

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

import UIKit
import BidMachine

class InterstitialController: UIViewController {
    
    private var interstitial: BDMInterstitial?
    
    func load() {
        let interstitial = BDMInterstitial()
        let request = BDMInterstitialRequest()
        
        interstitial.delegate = self
        interstitial.populate(with: request)
        
        self.interstitial = interstitial
    }
    
    func present() {
        guard let interstitial = self.interstitial, interstitial.canShow else {
            return
        }
        
        interstitial.present(fromRootViewController: self)
    }
}

extension InterstitialController: BDMInterstitialDelegate {
    
    func interstitialReady(toPresent interstitial: BDMInterstitial) {
        
    }
    
    func interstitial(_ interstitial: BDMInterstitial, failedWithError error: Error) {
        
    }
    
    func interstitial(_ interstitial: BDMInterstitial, failedToPresentWithError error: Error) {
        
    }
    
    func interstitialWillPresent(_ interstitial: BDMInterstitial) {
        
    }
    
    func interstitialDidDismiss(_ interstitial: BDMInterstitial) {
        
    }
    
    func interstitialRecieveUserInteraction(_ interstitial: BDMInterstitial) {
        
    }
}
#import "InterstitialController.h"
#import <BidMachine/BidMachine.h>

@interface InterstitialController ()<BDMInterstitialDelegate>

@property (nonatomic, strong) BDMInterstitial *interstitial;

@end

@implementation InterstitialController

- (void)load {
    
    BDMInterstitialRequest *request = [BDMInterstitialRequest new];
    BDMInterstitial *interstitial = [BDMInterstitial new];
    
    interstitial.delegate = self;
    [interstitial populateWithRequest:request];
    
    self.interstitial = interstitial;
}

- (void)show {
    if ([self.interstitial canShow]) {
        [self.interstitial presentFromRootViewController:self];
    }
}

#pragma mark - BDMInterstitialDelegate

- (void)interstitialReadyToPresent:(nonnull BDMInterstitial *)interstitial {
    
}

- (void)interstitial:(nonnull BDMInterstitial *)interstitial failedWithError:(nonnull NSError *)error {
    
}

- (void)interstitial:(nonnull BDMInterstitial *)interstitial failedToPresentWithError:(nonnull NSError *)error {
    
}

- (void)interstitialWillPresent:(nonnull BDMInterstitial *)interstitial {
    
}

- (void)interstitialDidDismiss:(nonnull BDMInterstitial *)interstitial {
    
}

- (void)interstitialRecieveUserInteraction:(nonnull BDMInterstitial *)interstitial {
    
}

@end

Advanced Loading

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

🚧

Warning

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

import UIKit
import BidMachine

class AdvancedInterstitialController: UIViewController {

    private var interstitial: BDMInterstitial?
    private var request: BDMInterstitialRequest?
    
    func load() {
        let request = BDMInterstitialRequest()
        request.perform(with: self)
        
        self.request = request
    }
    
    func present() {
        guard let interstitial = self.interstitial, interstitial.canShow else {
            return
        }
        
        interstitial.present(fromRootViewController: self)
    }
}

extension AdvancedInterstitialController: BDMRequestDelegate {
    
    func requestDidExpire(_ request: BDMRequest) {
        
    }
    
    func request(_ request: BDMRequest, failedWithError error: Error) {
        
    }
    
    func request(_ request: BDMRequest, completeWith info: BDMAuctionInfo) {
        guard
            let request = request as? BDMInterstitialRequest
        else { return }
        
        let interstitial = BDMInterstitial()
        interstitial.delegate = self
        interstitial.populate(with: request)
        
        self.interstitial = interstitial
    }
}

extension AdvancedInterstitialController: BDMInterstitialDelegate {

    func interstitialReady(toPresent interstitial: BDMInterstitial) {
        
    }
    
    func interstitial(_ interstitial: BDMInterstitial, failedWithError error: Error) {
        
    }
    
    func interstitial(_ interstitial: BDMInterstitial, failedToPresentWithError error: Error) {
        
    }
    
    func interstitialWillPresent(_ interstitial: BDMInterstitial) {
        
    }
    
    func interstitialDidDismiss(_ interstitial: BDMInterstitial) {
        
    }
    
    func interstitialRecieveUserInteraction(_ interstitial: BDMInterstitial) {
        
    }
}
#import "AdvancedInterstitialController.h"
#import <BidMachine/BidMachine.h>

@interface AdvancedInterstitialController ()<BDMRequestDelegate, BDMInterstitialDelegate>

@property (nonatomic, strong) BDMInterstitial *interstitial;
@property (nonatomic, strong) BDMInterstitialRequest *request;

@end

@implementation AdvancedInterstitialController

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

- (void)show {
    if ([self.interstitial canShow]) {
        [self.interstitial presentFromRootViewController:self];
    }
}

#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.interstitial = [BDMInterstitial new];
    self.interstitial.delegate = self;
    [self.interstitial populateWithRequest:(BDMInterstitialRequest *)request];
}

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

#pragma mark - BDMInterstitialDelegate

- (void)interstitialReadyToPresent:(nonnull BDMInterstitial *)interstitial {
    
}

- (void)interstitial:(nonnull BDMInterstitial *)interstitial failedWithError:(nonnull NSError *)error {
    
}

- (void)interstitial:(nonnull BDMInterstitial *)interstitial failedToPresentWithError:(nonnull NSError *)error {
    
}

- (void)interstitialWillPresent:(nonnull BDMInterstitial *)interstitial {
    
}

- (void)interstitialDidDismiss:(nonnull BDMInterstitial *)interstitial {
    
}

- (void)interstitialRecieveUserInteraction:(nonnull BDMInterstitial *)interstitial {
    
}

@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
}

BDMInterstitialDelegate

extension YourViewController: BDMInterstitialDelegate {
    func interstitialReady(toPresent interstitial: BDMInterstitial) {
        /// Called in case interstitial ready to present
        /// creative
    }
    
    func interstitial(_ interstitial: BDMInterstitial, failedWithError error: Error) {
        /// Called in case interstitial can't be load at this time for some reason.
    }
   
    func interstitial(_ interstitial: BDMInterstitial, failedToPresentWithError error: Error) {
        /// Called in case interstitial can't be present at this time for some reason.
        /// Please check that interstitial not ready before load new instance
    }
   
    func interstitialWillPresent(_ interstitial: BDMInterstitial) {
        /// Called before interstitial present fullscreen ad.
        /// You should mute app, stop rendering any data, etc after this
        /// callback triggered
    }
   
    func interstitialDidDismiss(_ interstitial: BDMInterstitial) {
        /// Called after interstitial dismiss fullscreen ad.
        /// You can unmute app, start rendering any data, etc after this
        /// callback triggered
    }
   
    func interstitialRecieveUserInteraction(_ interstitial: BDMInterstitial) {
        /// Called when interstitial handle touch event. After this callback BidMachine try to
        /// open product link in StoreKit, Safari view controller or
        /// external browser
    }
}
#pragma mark - BDMInterstitialDelegate
 
- (void)interstitial:(BDMInterstitial *)interstitial failedToPresentWithError:(NSError *)error {
    /// Called in case interstitial can't be present at this time for some reason.
    /// Please check that interstitial not ready before load new instance
}
 
- (void)interstitial:(BDMInterstitial *)interstitial failedWithError:(NSError *)error {
    /// Called in case interstitial can't be load at this time for some reason.
}
 
- (void)interstitialReadyToPresentAd:(BDMInterstitial *)interstitial {
    /// Called in case interstitial ready to present
    /// creative
}
 
- (void)interstitialDidDismiss:(BDMInterstitial *)interstitial {
    /// Called after interstitial dismiss fullscreen ad.
    /// You can unmute app, start rendering any data, etc after this
    /// callback triggered
}
 
- (void)interstitialRecieveUserInteraction:(BDMInterstitial *)interstitial {
    /// Called when interstitial handle touch event. After this callback BidMachine try to
    /// open product link in StoreKit, Safari view controller or
    /// external browser
}
 
- (void)interstitialWillPresent:(BDMInterstitial *)interstitial {
    /// Called before interstitial present fullscreen ad.
    /// You should mute app, stop rendering any data, etc after this
    /// callback triggered
}

BDMAdEventProducerDelegate

extension YourViewController {

     func updateDelegate() {

         self.interstitial.producerDelegate = self
     }
}

extension YourViewController: 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.interstitial.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
}