Rewarded implementation

📘

First you need to load ad request from BidMachine

self.rewardedRequest = [BDMRewardedRequest new];
[self.rewardedRequest performWithDelegate:self];
let rewardedRequest = BDMRewardedRequest()
rewardedRequest.perform(with: self)
self.rewardedRequest = rewardedRequest

📘

After loading the request, you need to load GAM ad with BidMachine request parameters.

❗️

Don't forget to install adMetadataDelegate

#pragma mark - BDMRequestDelegate

- (void)request:(BDMRequest *)request completeWithInfo:(BDMAuctionInfo *)info {
    __weak __typeof__(self) weakSelf = self;
    
    GAMRequest *adMobRequest = [GAMRequest request];
    adMobRequest.customTargeting = request.info.customParams;
    
    [GADRewardedAd loadWithAdUnitID:@UNIT_ID
                            request:adMobRequest
                  completionHandler:^(GADRewardedAd * _Nullable rewardedAd,
                                      NSError * _Nullable error) {
        if (error) {
            // FAIL LOAD
        } else {
            // WAIT AD EVENT DELEGATE
            weakSelf.adMobRewarded = rewardedAd;
            weakSelf.adMobRewarded.adMetadataDelegate = weakSelf;
        }
    }];
}
//MARK: BDMRequestDelegate

func request(_ request: BDMRequest, completeWith info: BDMAuctionInfo) {
        let adMobRequest = GAMRequest()
        adMobRequest.customTargeting = info.customParams.compactMapValues { $0 as? String }
        GADRewardedAd.load(withAdUnitID: UNIT_ID, request: adMobRequest) { [weak self] rewardedAd, error in
            guard let self = self, let rewardedAd = rewardedAd, error == nil else { return }
            rewardedAd.adMetadataDelegate = self
            self.adMobRewarded = rewardedAd
        }
    }

📘

If the GAM Ad loads successfully, you need to listen events delegate.
If the event name matches the registered event for BidMachine, then you need to load the ad via BidMachine. If it does not match, then show through GAM

- (void)adMetadataDidChange:(nonnull id<GADAdMetadataProvider>)ad {
    if (![ad.adMetadata[@"AdTitle"] isEqual:@"bidmachine-rewarded"]) {
        // SHOW GADRewardedAd
    } else {
        self.rewarded = [BDMRewarded new];
        self.rewarded.delegate = self;
        [self.rewarded populateWithRequest:self.rewardedRequest];
    }
}
func adMetadataDidChange(_ ad: GADAdMetadataProvider) {
        let data = ad.adMetadata.flatMap {$0.compactMapValues { $0 as? String }}
        let key = GADAdMetadataKey(rawValue: "AdTitle")
        if let data = data, let name = data[key], let rewardedRequest = rewardedRequest, name == "bidmachine-rewarded" {
            let rewarded = BDMRewarded()
            rewarded.delegate = self
            rewarded.populate(with: rewardedRequest)
            self.rewarded = rewarded
        } else {
            // SHOW GADRewardedAd
        }
    }
#pragma mark - BDMRewardedDelegate

- (void)rewardedReadyToPresent:(nonnull BDMRewarded *)rewarded {
    [rewarded presentFromRootViewController:self];
}
//MARK: BDMRewardedDelegate

func rewardedReady(toPresent rewarded: BDMRewarded) {
        rewarded.present(fromRootViewController: self)
    }