Interstitial

Interstitial implementation

📘

First you need to load ad request from BidMachine

self.interstitialRequest = [BDMInterstitialRequest new];
[self.interstitialRequest performWithDelegate:self];
let interstitialRequest = BDMInterstitialRequest()
interstitialRequest.perform(with: self)
self.interstitialRequest = interstitialRequest

📘

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

❗️

Don't forget to install appEventDelegate

#pragma mark - BDMRequestDelegate

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

func request(_ request: BDMRequest, completeWith info: BDMAuctionInfo) {
        
        let adMobRequest = GAMRequest()
        adMobRequest.customTargeting = info.customParams.compactMapValues { $0 as? String }
        
        GAMInterstitialAd.load(withAdManagerAdUnitID: UNIT_ID, request: adMobRequest) { [weak self] interstitialAd,     error in
            guard let self = self, let interstitialAd = interstitialAd, error == nil else { return }
            interstitialAd.appEventDelegate = self
            self.adMobInterstitial = interstitialAd
        }
    }

📘

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

#pragma mark - GADAppEventDelegate

- (void)interstitialAd:(nonnull GADInterstitialAd *)interstitialAd
    didReceiveAppEvent:(nonnull NSString *)name
              withInfo:(nullable NSString *)info {
    
    if ([name isEqualToString:@"bidmachine-interstitial"]) {
        self.interstitial = [BDMInterstitial new];
        self.interstitial.delegate = self;
        [self.interstitial populateWithRequest:self.interstitialRequest];
    } else {
        // SHOW GADInterstitialAd
    }
}
//MARK: GADAppEventDelegate

func interstitialAd(_ interstitialAd: GADInterstitialAd, didReceiveAppEvent name: String, withInfo info: String?) {
        if name == "bidmachine-interstitial" {
            guard let interstitialRequest = interstitialRequest else { return}

            let interstitial = BDMInterstitial()
            interstitial.delegate = self
            interstitial.populate(with: interstitialRequest)
            self.interstitial = interstitial
        } else {
            // SHOW GADInterstitialAd
        }
    }
#pragma mark - BDMInterstitialDelegate

- (void)interstitialReadyToPresent:(nonnull BDMInterstitial *)interstitial {
    [interstitial presentFromRootViewController:self];
}
//MARK: BDMInterstitialDelegate

func interstitialReady(toPresent interstitial: BDMInterstitial) {
    interstitial.present(fromRootViewController: self)
}