Default Loading

Native ads support the NAST ad format. BDMNativeAd works this BDMNativeAdRequest.

You can call -makeRequest: method with a ready or idle native request object.

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

import UIKit
import BidMachine

class NativeAdRendering: UIView, BDMNativeAdRendering {
    
    private var _titleLabel         = UILabel()
    private var _callToActionLabel  = UILabel()
    private var _descriptionLabel   = UILabel()
    
    func prepare() {
        // Place design on UIView
    }
    
    func titleLabel() -> UILabel {
        return self._titleLabel
    }
    
    func callToActionLabel() -> UILabel {
        return self._callToActionLabel
    }
    
    func descriptionLabel() -> UILabel {
        return self._descriptionLabel
    }
}

class NativeAdController: UIViewController {
    
    private var nativeAd: BDMNativeAd?
    
    func load() {
        let nativeAd = BDMNativeAd()
        let request = BDMNativeAdRequest()
        
        nativeAd.delegate = self
        nativeAd.make(request)
        
        self.nativeAd = nativeAd
    }
    
    func present() {
        guard let nativeAd = self.nativeAd, nativeAd.canShow else {
            return
        }
        
        let renderingView = NativeAdRendering(frame: CGRect(x: 0, y: 0, width: 300, height: 250))
        renderingView.prepare()
        
        self.view.addSubview(renderingView)
        
        nativeAd.unregisterViews()
        nativeAd.present(on: renderingView,
                         clickableViews: [],
                         adRendering: renderingView,
                         controller: self,
                         error: nil)
    }

}

extension NativeAdController: BDMNativeAdDelegate {
    
    func nativeAd(_ nativeAd: BDMNativeAd, readyToPresentAd auctionInfo: BDMAuctionInfo) {
        
    }
    
    func nativeAd(_ nativeAd: BDMNativeAd, failedWithError error: Error) {
        
    }
}
#import "NativeAdController.h"
#import <BidMachine/BidMachine.h>

@interface NativeAdRendering : UIView <BDMNativeAdRendering>

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *callToActionLabel;
@property (nonatomic, strong) UILabel *descriptionLabel;

- (void)prepare;

@end

@implementation NativeAdRendering

- (void)prepare {
    // Place design on UIView
}

@end

@interface NativeAdController ()<BDMNativeAdDelegate>

@property (nonatomic, strong) BDMNativeAd *nativeAd;

@end

@implementation NativeAdController

- (void)load {
    
    BDMNativeAdRequest *request = [BDMNativeAdRequest new];
    BDMNativeAd *nativeAd = [BDMNativeAd new];
    
    nativeAd.delegate = self;
    [nativeAd makeRequest:request];
    
    self.nativeAd = nativeAd;
}

- (void)show {
    if (![self.nativeAd canShow]) {
        return;
    }
    
    NativeAdRendering *renderingView = [[NativeAdRendering alloc] initWithFrame:(CGRect){.size = CGSizeMake(300, 250)}];
    [renderingView prepare];
    
    [self.view addSubview:renderingView];
    
    [self.nativeAd unregisterViews];
    [self.nativeAd presentOn:renderingView
              clickableViews:@[]
                 adRendering:renderingView
                  controller:self
                       error:nil];
}

#pragma mark - BDMNativeAdDelegate

- (void)nativeAd:(nonnull BDMNativeAd *)nativeAd readyToPresentAd:(nonnull BDMAuctionInfo *)auctionInfo {
    
}

- (void)nativeAd:(nonnull BDMNativeAd *)nativeAd failedWithError:(nonnull NSError *)error {
    
}

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

BDMNativeAdDelegate

extension YourViewController: BDMNativeAdDelegate {
    func nativeAd(_ nativeAd: BDMNativeAd, readyToPresentAd auctionInfo: BDMAuctionInfo) {
        /// Called when native ad ready to present ad
    }
    
    func nativeAd(_ nativeAd: BDMNativeAd, failedWithError error: Error) {
        /// Called in case native can't be load at this time for some reason.
    }
}
#pragma mark - BDMNativeAdDelegate
 
- (void)nativeAd:(nonnull BDMNativeAd *)nativeAd failedWithError:(nonnull NSError *)error {
    /// Called in case native can't be load at this time for some reason.
}
 
- (void)nativeAd:(nonnull BDMNativeAd *)nativeAd readyToPresentAd:(nonnull BDMAuctionInfo *)auctionInfo {
    /// Called when native ad ready to present ad
}

BDMAdEventProducerDelegate

extension YourViewController {

     func updateDelegate() {

         self.nativeAd.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.nativeAd.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
}