Documentation

Ad Object

Ad object serves to download and display ads

Prepare Ad object

  • To prepare an ad object, first you need to create a request of the type you want to load
  • Then you need to request an ad. For example:
let config = try? BidMachineSdk.shared.requestConfiguration(.banner)
BidMachineSdk.shared.ad(config) { [weak self] ad, error in
   guard let self = self else {
      return
   }
   self.ad = ad
}
id<BidMachineRequestConfigurationProtocol> config = [BidMachineSdk.shared requestConfiguration:BidMachinePlacementFormatBanner error:&error];
[BidMachineSdk.shared ad:config :^(id<BidMachineAdProtocol> _Nullable ad, NSError * _Nullable error) {
   self.ad = ad;
}];

🚧

Placement specific

To load a typed ad see the section below

Prepared ad contains AuctionInfo and RequestInfo

Auction Info

_ = ad.auctionInfo.bidId
_ = ad.auctionInfo.creativeId
_ = ad.auctionInfo.dealId
_ = ad.auctionInfo.cId
_ = ad.auctionInfo.demandSource
_ = ad.auctionInfo.price
_ = ad.auctionInfo.customParams
_ = ad.auctionInfo.customExtras
[banner.auctionInfo bidId];
[banner.auctionInfo creativeId];
[banner.auctionInfo dealId];
[banner.auctionInfo cId];
[banner.auctionInfo demandSource];
[banner.auctionInfo price];
[banner.auctionInfo customParams];
[banner.auctionInfo customExtras];
ParameterTypeDescription
bidIdStringUnique bid identifier.
creativeIdOptional StringUnique creative identifier.
dealIdOptional StringUnique deal identifier.
cIdOptional StringCampaign ID or other similar grouping of brand-related ads.
demandSourceStringName of demand source.
priceDoubleBid price.
customParamsDictionary of String - AnyServer custom params
customExtrasDictionary of String - AnyWinner header bidding unit extras params

Delegate

You can subscribe to a delegate

ad.delegate = self
ad.delegate = self;
func didLoadAd(_ ad : BidMachineAdProtocol) {}

func didFailLoadAd(_ ad : BidMachineAdProtocol, _ error : Error) {}

func didPresentAd(_ ad : BidMachineAdProtocol) {}

func didFailPresentAd(_ ad : BidMachineAdProtocol, _ error : Error) {}

func didDismissAd(_ ad : BidMachineAdProtocol) {}

func willPresentScreen(_ ad : BidMachineAdProtocol) {}

func didDismissScreen(_ ad : BidMachineAdProtocol) {}

func didUserInteraction(_ ad : BidMachineAdProtocol) {}

func didExpired(_ ad : BidMachineAdProtocol) {}

func didTrackImpression(_ ad : BidMachineAdProtocol) {}

func didTrackInteraction(_ ad : BidMachineAdProtocol) {}

func didReceiveReward(_ ad : BidMachineAdProtocol) {}
- (void)didLoadAd:(id<BidMachineAdProtocol> _Nonnull)ad { 
    
}

- (void)didFailLoadAd:(id<BidMachineAdProtocol> _Nonnull)ad :(NSError * _Nonnull)error { 
    
}

- (void)didPresentAd:(id<BidMachineAdProtocol> _Nonnull)ad { 
    
}

- (void)didFailPresentAd:(id<BidMachineAdProtocol> _Nonnull)ad :(NSError * _Nonnull)error { 
    
}

- (void)didDismissAd:(id<BidMachineAdProtocol> _Nonnull)ad { 
   
}

- (void)willPresentScreen:(id<BidMachineAdProtocol> _Nonnull)ad { 
    
}

- (void)didDismissScreen:(id<BidMachineAdProtocol> _Nonnull)ad { 
   
}

- (void)didUserInteraction:(id<BidMachineAdProtocol> _Nonnull)ad { 
    
}

- (void)didExpired:(id<BidMachineAdProtocol> _Nonnull)ad { 
    
}

- (void)didTrackImpression:(id<BidMachineAdProtocol> _Nonnull)ad { 
    
}

- (void)didTrackInteraction:(id<BidMachineAdProtocol> _Nonnull)ad { 
    
}

- (void)didReceiveReward:(id<BidMachineAdProtocol> _Nonnull)ad { 
    
}

Load ad

To load a creative, you need to call the load method

🚧

Controller && Delegate

Before loading, make sure to install Delegate and Controller

ad.controller = self
ad.delegate = self
ad.loadAd()
ad.controller = self;
ad.delegate = self;
[ad loadAd];

Ad placement specific

Banner

Load

let config = try? BidMachineSdk.shared.requestConfiguration(.banner)
BidMachineSdk.shared.banner(config) { [weak self] ad, error in
   guard let self = self else {
       return
   }
   self.banner = ad
   self.banner.controller = self
   self.banner.delegate = self
   self.bannerd.loadAd()
}
id<BidMachineRequestConfigurationProtocol> config = [BidMachineSdk.shared requestConfiguration:BidMachinePlacementFormatBanner error:&error];
[BidMachineSdk.shared banner:config :^(BidMachineBanner * _Nullable banner, NSError * _Nullable error) {
  banner.controller = self;
  banner.delegate = self;
  [banner loadAd];  
  self.banner = banner;
}];

Present

self.view.addSubview(banner)
[self.view addSubview:self.banner];

Interstitial

Load

let config = try? BidMachineSdk.shared.requestConfiguration(.interstitial)
BidMachineSdk.shared.interstitial(config) { [weak self] ad, error in
   guard let self = self else {
       return
   }
   self.interstitial = ad
   self.interstitial.controller = self
   self.interstitial.delegate = self
   self.interstitial.loadAd()
}
id<BidMachineRequestConfigurationProtocol> config = [BidMachineSdk.shared requestConfiguration:BidMachinePlacementFormatInterstitial error:&error];
[BidMachineSdk.shared interstitial:config :^(BidMachineInterstitial * _Nullable interstitial, NSError * _Nullable error) {
  interstitial.controller = self;
  interstitial.delegate = self;
  [interstitial loadAd];  
  self.interstitial = interstitial;
}];

Present

interstitial.presentAd()
[self.interstitial presentAd];

Rewarded

Load

let config = try? BidMachineSdk.shared.requestConfiguration(.rewarded)
BidMachineSdk.shared.rewarded(config) { [weak self] ad, error in
   guard let self = self else {
       return
   }
   self.rewarded = ad
   self.rewarded.controller = self
   self.rewarded.delegate = self
   self.rewarded.loadAd()
}
id<BidMachineRequestConfigurationProtocol> config = [BidMachineSdk.shared requestConfiguration:BidMachinePlacementFormatRewarded error:&error];
[BidMachineSdk.shared rewarded:config :^(BidMachineRewarded * _Nullable rewarded, NSError * _Nullable error) {
  rewarded.controller = self;
  rewarded.delegate = self;
  [rewarded loadAd];  
  self.rewarded = rewarded;
}];

Present

rewarded.presentAd()
[self.rewarded presentAd];

Native

Load

let config = try? BidMachineSdk.shared.requestConfiguration(.native)
BidMachineSdk.shared.native(config) { [weak self] ad, error in
   guard let self = self else {
       return
   }
   self.native = ad
   self.native.controller = self
   self.native.delegate = self
   self.native.loadAd()
}
id<BidMachineRequestConfigurationProtocol> config = [BidMachineSdk.shared requestConfiguration:BidMachinePlacementFormatNative error:&error];
[BidMachineSdk.shared native:config :^(BidMachineNative * _Nullable native, NSError * _Nullable error) {
  native.controller = self;
  native.delegate = self;
  [native loadAd];  
  self.native = native;
}];

Present

When displaying ads, you must pass a set of assets through the BidMachineNativeAdRendering protocol

@objc public protocol BidMachineNativeAdRendering {
    
    var titleLabel: UILabel? { get }
    
    var callToActionLabel: UILabel? { get }
    
    var descriptionLabel: UILabel? { get }
    
    var iconView: UIImageView? { get }
    
    var mediaContainerView: UIView? { get }
    
    var adChoiceView: UIView? { get }
}
//Where rendering - BidMachineNativeAdRendering protocol
try native.presentAd(self.nativeContainer, rendering)
//Where rendering - BidMachineNativeAdRendering protocol
NSError *error;
[native presentAd:self.container :rendering error:&error];

MediaView

Load

let config = try? BidMachineSdk.shared.requestConfiguration(.media)
BidMachineSdk.shared.media(config) { [weak self] ad, error in
   guard let self = self else {
       return
   }
   self.media = ad
   self.media.controller = self
   self.media.delegate = self
   self.media.loadAd()
}
id<BidMachineRequestConfigurationProtocol> config = [BidMachineSdk.shared requestConfiguration:BidMachinePlacementFormatMedia error:&error];
[BidMachineSdk.shared media:config :^(BidMachineMedia * _Nullable media, NSError * _Nullable error) {
  media.controller = self;
  media.delegate = self;
  [media loadAd];  
  self.media = media;
}];

Present

self.view.addSubview(media)
[self.view addSubview:self.banner];

Playback control

media.resume()
media.pause()
media.mute()
media.unmute()
[self.media.resume];
[self.media.pause];
[self.media.mute];
[self.media unmute];