Documentation
Log In
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:
guard let placement = try? BidMachineSdk.shared.placement(from: .banner) else { return }
let request = BidMachineSdk.shared.auctionRequest(placement: placement)
BidMachineSdk.shared.ad(request: request) { [weak self] ad, error in
   guard let self = self else {
      return
   }
   self.ad = ad
}
NSError *error = nil;
BidMachinePlacement *placement = [[BidMachineSdk shared] placementFrom:PlacementFormatBanner
                                                                builder:nil
                                                                  error:&error];
if (!placement) {
    return;
}

BidMachineAuctionRequest *request = [[BidMachineSdk shared] auctionRequestWithPlacement:placement builder:nil];
__weak typeof(self) weakSelf = self;
[[BidMachineSdk shared] adWithRequest:request
                           completion:^(id<BidMachineAdProtocol> _Nullable ad, NSError * _Nullable error) {
    __strong typeof(weakSelf) strongSelf = weakSelf;
    if (!strongSelf) {
        return;
    }
    strongSelf.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

guard let placement = try? BidMachineSdk.shared.placement(from: .banner) else { return }
let request = BidMachineSdk.shared.auctionRequest(placement: placement)

BidMachineSdk.shared.banner(request: request) { [weak self] ad, error in
   guard let self = self else {
       return
   }
   self.banner = ad
   self.banner.controller = self
   self.banner.delegate = self
   self.banner.loadAd()
}
NSError *error = nil;
BidMachinePlacement *placement = [[BidMachineSdk shared] placementFrom:PlacementFormatBanner
                                                                builder:nil
                                                                  error:&error];
if (!placement) {
    return;
}

BidMachineAuctionRequest *request = [[BidMachineSdk shared] auctionRequestWithPlacement:placement builder:nil];

__weak typeof(self) weakSelf = self;
[[BidMachineSdk shared] bannerWithRequest:request
                               completion:^(BidMachineBanner * ad, NSError * _Nullable error) {
    __strong typeof(weakSelf) strongSelf = weakSelf;
    if (!strongSelf) {
        return;
    }
    strongSelf.banner = ad;
    strongSelf.banner.controller = strongSelf;
    strongSelf.banner.delegate = strongSelf;
    [strongSelf.banner loadAd];
}];

Present

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

Interstitial

Load

guard let placement = try? BidMachineSdk.shared.placement(from: .interstitial) else { return }
let request = BidMachineSdk.shared.auctionRequest(placement: placement)
BidMachineSdk.shared.interstitial(request: request) { [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()
}
NSError *error = nil;
BidMachinePlacement *placement = [[BidMachineSdk shared] placementFrom:PlacementFormatInterstitial
                                                                builder:nil
                                                                  error:&error];
if (!placement) {
    return;
}

BidMachineAuctionRequest *request = [[BidMachineSdk shared] auctionRequestWithPlacement:placement
                                                                                 builder:nil];

__weak typeof(self) weakSelf = self;
[[BidMachineSdk shared] interstitialWithRequest:request
                                     completion:^(BidMachineInterstitial *ad, NSError * _Nullable error) {
    __strong typeof(weakSelf) strongSelf = weakSelf;
    if (!strongSelf) {
        return;
    }
    strongSelf.interstitial = ad;
    strongSelf.interstitial.controller = strongSelf;
    strongSelf.interstitial.delegate = strongSelf;
    [strongSelf.interstitial loadAd];
}];

Present

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

Rewarded

Load

guard let placement = try? BidMachineSdk.shared.placement(from: .rewarded) else { return }
let request = BidMachineSdk.shared.auctionRequest(placement: placement)
BidMachineSdk.shared.rewarded(request: request) { [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()
}
NSError *error = nil;
BidMachinePlacement *placement = [[BidMachineSdk shared] placementFrom:PlacementFormatRewarded
                                                                builder:nil
                                                                  error:&error];
if (!placement) {
    return;
}

BidMachineAuctionRequest *request = [[BidMachineSdk shared] auctionRequestWithPlacement:placement
                                                                                 builder:nil];

__weak typeof(self) weakSelf = self;
[[BidMachineSdk shared] rewardedWithRequest:request
                                 completion:^(BidMachineRewarded *ad, NSError * _Nullable error) {
    __strong typeof(weakSelf) strongSelf = weakSelf;
    if (!strongSelf) {
        return;
    }
    strongSelf.rewarded = ad;
    strongSelf.rewarded.controller = strongSelf;
    strongSelf.rewarded.delegate = strongSelf;
    [strongSelf.rewarded loadAd];
}];

Present

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

Native

Load

guard let placement = try? BidMachineSdk.shared.placement(from: .native) else { return }
let request = BidMachineSdk.shared.auctionRequest(placement: placement)
BidMachineSdk.shared.native(request: request) { [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()
}
NSError *error = nil;
BidMachinePlacement *placement = [[BidMachineSdk shared] placementFrom:PlacementFormatNative
                                                                builder:nil
                                                                  error:&error];
if (!placement) {
    return;
}

BidMachineAuctionRequest *request = [[BidMachineSdk shared] auctionRequestWithPlacement:placement
                                                                                 builder:nil];

__weak typeof(self) weakSelf = self;
[[BidMachineSdk shared] nativeWithRequest:request
                               completion:^(BidMachineNative *ad, NSError * _Nullable error) {
    __strong typeof(weakSelf) strongSelf = weakSelf;
    if (!strongSelf) {
        return;
    }
    strongSelf.native = ad;
    strongSelf.native.controller = strongSelf;
    strongSelf.native.delegate = strongSelf;
    [strongSelf.native loadAd];
}];

Present

When displaying ads, you must pass a set of assets through the BidMachineNativeAdRendering protocol. And register the asset for the click

@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 }
}
@objc public enum BidMachineNativeAdRenderingAssetType: Int {

    case titleLabel

    case callToActionLabel

    case descriptionLabel

    case iconView

    case mediaContainerView

    case adChoiceView
}

//Where rendering - BidMachineNativeAdRendering protocol
native.registerAssetsForInteraction([BidMachineNativeAdRenderingAssetType.descriptionLabel.rawValue])
try native.presentAd(self.nativeContainer, rendering)
//Where rendering - BidMachineNativeAdRendering protocol
NSError *error;
[native registerAssetsForInteraction:@[@(BidMachineNativeAdRenderingAssetTypeDescriptionLabel)]]
[native presentAd:self.container :rendering error:&error];