Banner implementation

📘

First you need to load ad request from BidMachine

🚧

MREC load requires a different size

self.bannerRequest = [BDMBannerRequest new];
//    self.bannerRequest.adSize = BDMBannerAdSize320x50;
//    self.bannerRequest.adSize = BDMBannerAdSize300x250;
[self.bannerRequest performWithDelegate:self];
let bannerRequest = BDMBannerRequest()
//bannerRequest.adSize = BDMBannerAdSize.size320x50
//bannerRequest.adSize = BDMBannerAdSize.size300x250
bannerRequest.perform(with: self)
self.bannerRequest = bannerRequest

📘

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

❗️

Don't forget to install appEventDelegate

#pragma mark - BDMRequestDelegate

- (void)request:(BDMRequest *)request completeWithInfo:(BDMAuctionInfo *)info {
    GAMRequest *adMobRequest = [GAMRequest request];
    adMobRequest.customTargeting = request.info.customParams;
    
    self.adMobBanner = [[GAMBannerView alloc] initWithAdSize:GADAdSizeBanner];
    self.adMobBanner.delegate = self;
    self.adMobBanner.adUnitID = @UNIT_ID;
    self.adMobBanner.rootViewController = [[UIApplication.sharedApplication keyWindow] rootViewController];
    self.adMobBanner.appEventDelegate = self;

    [self.adMobBanner loadRequest:adMobRequest];
}
//MARK: BDMRequestDelegate

 func request(_ request: BDMRequest, completeWith info: BDMAuctionInfo) {
        let adMobRequest = GAMRequest()
        adMobRequest.customTargeting = info.customParams.compactMapValues { $0 as? String }
        
        let adMobBanner = GAMBannerView(adSize: GADAdSizeBanner)
        adMobBanner.delegate = self
        adMobBanner.adUnitID = UNIT_ID
        adMobBanner.rootViewController = self
        adMobBanner.appEventDelegate = self
        adMobBanner.load(adMobRequest)
        
        self.adMobBanner = adMobBanner
    }

📘

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)bannerViewDidReceiveAd:(nonnull GADBannerView *)bannerView {
    // WAIT AD EVENT DELEGATE
}

- (void)bannerView:(nonnull GADBannerView *)bannerVie didFailToReceiveAdWithError:(nonnull NSError *)error {
    // FAIL LOAD
}

- (void)adView:(nonnull GADBannerView *)banner didReceiveAppEvent:(nonnull NSString *)name withInfo:(nullable NSString *)info {
    if ([name isEqualToString:@"bidmachine-banner"]) {
        self.banner = [BDMBannerView new];
        self.banner.delegate = self;
        [self.banner populateWithRequest:self.bannerRequest];
    } else {
        // SHOW GADBannerView
    }
}
func bannerViewDidReceiveAd(_ bannerView: GADBannerView) {
        // WAIT AD EVENT DELEGATE
    }

func bannerView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: Error) {
        // FAILED TO LOAD
    }


func adView(_ banner: GADBannerView, didReceiveAppEvent name: String, withInfo info: String?) {
        if name == "bidmachine-banner" {
            guard let bannerRequest = bannerRequest else {return}
            let banner = BDMBannerView()
            banner.delegate = self
            banner.populate(with: bannerRequest)
            self.banner = banner
        } else {
            // SHOW GADBannerView
        }
    }
#pragma mark - BDMBannerDelegate

- (void)bannerViewReadyToPresent:(nonnull BDMBannerView *)bannerView {
    [bannerView removeFromSuperview];
    [self.view addSubview: bannerView];
}
//MARK: BDMBannerDelegate

func bannerViewReady(toPresent bannerView: BDMBannerView) {
        bannerView.removeFromSuperview()
        container.addSubview(bannerView)
    }