Default Loading

Rewarded ads support both MRAID and VAST ad formats. BDMRewarded works this BDMRewardedRequest. Request object is described here.

You can call -populateWithRequest: method with ready or idle rewarded request object. In the second case, the request will be performed automatically.

You can also handle interstitial events. In this case some of your classes should implement BDMRewardedDelegate protocol. An instance of this class can be passed to banner view at any time of interstitial's lifecycle.

import UIKit
import BidMachine

class RewardedController: UIViewController {

    private var rewarded: BDMRewarded?
    
    func load() {
        let rewarded = BDMRewarded()
        let request = BDMRewardedRequest()
        
        rewarded.delegate = self
        rewarded.populate(with: request)
        
        self.rewarded = rewarded
    }
    
    func present() {
        guard let rewarded = self.rewarded, rewarded.canShow else {
            return
        }
        
        rewarded.present(fromRootViewController: self)
    }

}

extension RewardedController: BDMRewardedDelegate {
    
    func rewardedReady(toPresent rewarded: BDMRewarded) {
        
    }
    
    func rewarded(_ rewarded: BDMRewarded, failedWithError error: Error) {
        
    }
    
    func rewarded(_ rewarded: BDMRewarded, failedToPresentWithError error: Error) {
        
    }
    
    func rewardedWillPresent(_ rewarded: BDMRewarded) {
        
    }
    
    func rewardedDidDismiss(_ rewarded: BDMRewarded) {
        
    }
    
    func rewardedRecieveUserInteraction(_ rewarded: BDMRewarded) {
        
    }
    
    func rewardedFinishRewardAction(_ rewarded: BDMRewarded) {
        
    }
}
#import "RewardedController.h"
#import <BidMachine/BidMachine.h>

@interface RewardedController ()<BDMRewardedDelegate>

@property (nonatomic, strong) BDMRewarded *rewarded;

@end

@implementation RewardedController

- (void)load {
    
    BDMRewardedRequest *request = [BDMRewardedRequest new];
    BDMRewarded *rewarded = [BDMRewarded new];
    
    rewarded.delegate = self;
    [rewarded populateWithRequest:request];
    
    self.rewarded = rewarded;
}

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

#pragma mark - BDMRewardedDelegate

- (void)rewardedReadyToPresent:(nonnull BDMRewarded *)rewarded {
    
}

- (void)rewarded:(nonnull BDMRewarded *)rewarded failedWithError:(nonnull NSError *)error {
    
}

- (void)rewarded:(nonnull BDMRewarded *)rewarded failedToPresentWithError:(nonnull NSError *)error {
    
}

- (void)rewardedWillPresent:(nonnull BDMRewarded *)rewarded {
    
}

- (void)rewardedDidDismiss:(nonnull BDMRewarded *)rewarded {
    
}

- (void)rewardedRecieveUserInteraction:(nonnull BDMRewarded *)rewarded {
    
}

- (void)rewardedFinishRewardAction:(nonnull BDMRewarded *)rewarded {
    
}

@end

Advanced Loading

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

import UIKit
import BidMachine

class AdvancedRewardedController: UIViewController {

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

extension AdvancedRewardedController: BDMRequestDelegate {
    
    func requestDidExpire(_ request: BDMRequest) {
        
    }
    
    func request(_ request: BDMRequest, failedWithError error: Error) {
        
    }
    
    func request(_ request: BDMRequest, completeWith info: BDMAuctionInfo) {
        guard
            let request = request as? BDMRewardedRequest
        else { return }
        
        let rewarded = BDMRewarded()
        rewarded.delegate = self
        rewarded.populate(with: request)
        
        self.rewarded = rewarded
    }
}

extension AdvancedRewardedController: BDMRewardedDelegate {
    
    func rewardedReady(toPresent rewarded: BDMRewarded) {
        
    }
    
    func rewarded(_ rewarded: BDMRewarded, failedWithError error: Error) {
        
    }
    
    func rewarded(_ rewarded: BDMRewarded, failedToPresentWithError error: Error) {
        
    }
    
    func rewardedWillPresent(_ rewarded: BDMRewarded) {
        
    }
    
    func rewardedDidDismiss(_ rewarded: BDMRewarded) {
        
    }
    
    func rewardedRecieveUserInteraction(_ rewarded: BDMRewarded) {
        
    }
    
    func rewardedFinishRewardAction(_ rewarded: BDMRewarded) {
        
    }
}
#import "AdvancedRewardedController.h"
#import <BidMachine/BidMachine.h>

@interface AdvancedRewardedController ()<BDMRequestDelegate, BDMRewardedDelegate>

@property (nonatomic, strong) BDMRewarded *rewarded;
@property (nonatomic, strong) BDMRewardedRequest *request;

@end

@implementation AdvancedRewardedController

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

- (void)show {
    if ([self.rewarded canShow]) {
        [self.rewarded 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:BDMRewardedRequest.class]) {
        return;
    }
    
    self.rewarded = [BDMRewarded new];
    self.rewarded.delegate = self;
    [self.rewarded populateWithRequest:(BDMRewardedRequest *)request];
}

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

#pragma mark - BDMRewardedDelegate

- (void)rewardedReadyToPresent:(nonnull BDMRewarded *)rewarded {
    
}

- (void)rewarded:(nonnull BDMRewarded *)rewarded failedWithError:(nonnull NSError *)error {
    
}

- (void)rewarded:(nonnull BDMRewarded *)rewarded failedToPresentWithError:(nonnull NSError *)error {
    
}

- (void)rewardedWillPresent:(nonnull BDMRewarded *)rewarded {
    
}

- (void)rewardedDidDismiss:(nonnull BDMRewarded *)rewarded {
    
}

- (void)rewardedRecieveUserInteraction:(nonnull BDMRewarded *)rewarded {
    
}

- (void)rewardedFinishRewardAction:(nonnull BDMRewarded *)rewarded {
    
}

@end

Delegated Methods

🚧

Warning

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

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
}

BDMRewardedAdDelegate

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

BDMAdEventProducerDelegate

extension YourViewController {

     func updateDelegate() {

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