Documentation

Rewarded implementation

📘

First you need to load ad from BidMachine

BidMachineSdk.shared.rewarded { [weak self] (rewarded, error) in
    guard error == nil else { return }
    
    self?.bidMachineRewarded = rewarded
    self?.bidMachineRewarded.controller = viewController
    self?.bidMachineRewarded.delegate = self
    self?.bidMachineRewarded.loadAd()
}
__weak typeof(self) weakSelf = self;
[BidMachineSdk.shared rewarded:nil :^(BidMachineRewarded *rewarded, NSError *error) {
    if (error) {
        return;
    }
    weakSelf.bidMachineRewarded = rewarded;
    weakSelf.bidMachineRewarded.controller = weakSelf;
    weakSelf.bidMachineRewarded.delegate = weakSelf;
    [weakSelf.bidMachineRewarded loadAd];
}];

📘

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

❗️

Don't forget to install adMetadataDelegate

❗️

GAM request params should contains price with x.xx format

let priceFormatter: NumberFormatter = {
    let formatter = NumberFormatter()
    formatter.numberStyle = .decimal
    formatter.locale = Locale(identifier: "en_US_POSIX")
    formatter.roundingMode = .ceiling
    formatter.positiveFormat = "0.00"
    return formatter
}()

// MARK: BidMachineAdDelegate

func didLoadAd(_ ad: BidMachineAdProtocol) {
    var targeting = [String: String]()
    targeting["bm_pf"] = self.priceFormatter.string(from: NSNumber(value: ad.auctionInfo.price))
    
    let request = GAMRequest()
    request.customTargeting = targeting
    
    GADRewardedAd.load(
        withAdUnitID: "unit id",
        request: request,
        completionHandler: { rewarded, error in
            if let error {
                // FAIL LOAD
            } else {
                self.googleRewarded = interstitial
                self.googleRewarded?.adMetadataDelegate = self
            }
        }
    )
}
- (NSNumberFormatter *)formatter {
    static NSNumberFormatter *roundingFormater = nil;
    if (!roundingFormater) {
        roundingFormater = [NSNumberFormatter new];
        roundingFormater.numberStyle = NSNumberFormatterDecimalStyle;
        roundingFormater.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
        roundingFormater.roundingMode = NSNumberFormatterRoundCeiling;
        roundingFormater.positiveFormat = @"0.00";
    }
    return roundingFormater;
}


#pragma mark - BidMachineAdDelegate

- (void)didLoadAd:(id<BidMachineAdProtocol> _Nonnull)ad {
    GAMRequest *googleRequest = [GAMRequest request];
    googleRequest.customTargeting = @{
        @"bm_pf" : [self.formatter stringFromNumber:@(ad.auctionInfo.price)]
    };
    
    __weak typeof(self) weakSelf = self;
    [GADRewardedAd loadWithAdUnitID:@UNIT_ID
                            request:googleRequest
                  completionHandler:^(GADRewardedAd * _Nullable rewardedAd,
                                      NSError * _Nullable error) {
        if (error) {
             // FAIL LOAD
        } else {
            // WAIT AD EVENT DELEGATE
            weakSelf.googleRewarded = rewardedAd;
            weakSelf.googleRewarded.adMetadataDelegate = weakSelf;
        }
    }];
}

📘

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 show the ad via BidMachine. If it does not match, then show through GAM

// MARK: GADAdMetadataDelegate

func adMetadataDidChange(_ ad: GADAdMetadataProvider) {
    guard let adTitle = ad.adMetadata?[GADAdMetadataKey(rawValue: "AdTitle")] as? String else {
        return
    }
    
    switch adTitle {
    case "bidmachine-rewarded":
        // SHOW GADRewardedAd
    default:
        // SHOW BidMachine
    }
}
- (void)adMetadataDidChange:(nonnull id<GADAdMetadataProvider>)ad {
    if (![ad.adMetadata[@"AdTitle"] isEqual:@"bidmachine-rewarded"]) {
        // SHOW GADRewardedAd
    } else {
        // SHOW BidMachine
    }
}