💡Tips
- 🚀 Use preloading mechanism to enhance UX
- ⚠️ Handle lifecycle properly to prevent memory leaks
- 🔧 Recommended to use standardized callback workflow
#import <MCSDK/MCSDK.h>
@interface InterstitialVC () <MCAdDelegate, MCAdRevenueDelegate>
@property (nonatomic, strong) MCInterstitialAd *interstitialAd;
@property (nonatomic, assign) NSInteger retryAttempt;
@end
@implementation InterstitialVC
#define InterstitialPlacementID @"your mediation unit id"
//Scene ID
#define InterstitialSceneID @""
#pragma mark - Load Ad
- (void)loadAd {
if (!self.interstitialAd) {
self.interstitialAd = [[MCInterstitialAd alloc] initWithPlacementId:InterstitialPlacementID];
}
self.interstitialAd.delegate = self;
self.interstitialAd.revenueDelegate = self;
[self.interstitialAd loadAd];
}
#pragma mark - MCAdDelegate
// Ad load success
- (void)didLoadAd:(MCAdInfo *)ad {
// Reset retry attempt
self.retryAttempt = 0;
}
// Ad load failure
- (void)didFailToLoadAdWithError:(MCError *)error {
// We recommends that you retry with exponentially higher delays up to a maximum delay (in this case 8 seconds) or the maximum number of retries (in this case 3)
if (self.retryAttempt >= 3) {
return;
}
self.retryAttempt++;
NSInteger delaySec = pow(2, MIN(3, self.retryAttempt));
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delaySec * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self.interstitialAd loadAd];
});
}
// Ad display success
- (void)didDisplayAd:(MCAdInfo *)ad {
// pre-load
[self.interstitialAd loadAd];
}
// Ad closed
- (void)didHideAd:(MCAdInfo *)ad {
// pre-load
[self.interstitialAd loadAd];
}
// Ad click
- (void)didClickAd:(MCAdInfo *)ad {
}
// Ad display failure
- (void)didFailToDisplayAd:(MCAdInfo *)ad withError:(MCError *)error {
// pre-load
[self.interstitialAd loadAd];
}
- (void)didAdVideoStarted:(MCAdInfo *)ad { }
- (void)didAdVideoCompleted:(MCAdInfo *)ad { }
#pragma mark - MCAdRevenueDelegate
// Revenue tracking
- (void)didPayRevenueForAd:(MCAdInfo *)ad {
}
if ([self.interstitialAd isReady]) {
[self.interstitialAd showAdWithViewController:self withExtra:@{kMCAPIPlacementScenarioIDKey:@"your scene id"}];
} else {
[self.interstitialAd loadAd];
}
[self.interstitialAd destroyAd];
- (void)loadAd {
MCInterstitialAd *interstitialAd = [[MCInterstitialAd alloc] initWithPlacementId:self.placementID];
interstitialAd.delegate = self;
interstitialAd.revenueDelegate = self;
[interstitialAd setLoadExtraParameter:@{
@"userData": @"test_userData"
}];
[interstitialAd setExtraParameter:@{
@"test_extra_key": @"test_extra_value"
}];
[interstitialAd loadAd];
self.interstitialAd = interstitialAd;
}
- (void)didLoadAd:(MCAdInfo *)ad {
// Retrieve customized parameters
NSString *originDataJsonString = ad.originData;
}