💡Tips
- 🚀 Smart Cache automatically manages multi-placement parallel loading and cache comparison — no need to manually manage multiple
MCAppOpenAdinstances- ⚠️
MCAppOpenAdManageris a normal instance class; recommended to hold as a property; requiresUIWindowandUIViewControllerfor display- 🔧 Use
setAppOpenContainerView:to set the container view andsetLoadAdTimeout:to set load timeout
#import <MCSDK/MCSDK.h>
@interface SmartCacheAppOpenVC () <MCSmartCacheDelegate>
@property (nonatomic, strong) MCAppOpenAdManager *appOpenManager;
@end
@implementation SmartCacheAppOpenVC
#pragma mark - Load Ad
- (void)loadAd {
if (!self.appOpenManager) {
self.appOpenManager = [[MCAppOpenAdManager alloc] init];
}
// Set delegate before the first loadAd call
self.appOpenManager.delegate = self;
// (Optional) Set container view
// [self.appOpenManager setAppOpenContainerView:containerView];
// (Optional) Set load timeout in seconds (recommended 5-10 seconds)
// [self.appOpenManager setLoadAdTimeout:5.0];
[self.appOpenManager loadAd];
}
#pragma mark - MCSmartCacheDelegate
// At least one ad in cache pool is ready
- (void)smartCacheDidLoadAd:(MCAdInfo *)ad {
}
// All placements failed in first round (mutually exclusive with smartCacheDidLoadAd:)
- (void)smartCacheDidFailToLoadAdWithError:(MCError *)error {
}
// Current round loading completed
- (void)smartCacheDidAdLoadFinished {
}
// Ad displayed successfully
- (void)smartCacheDidDisplayAd:(MCAdInfo *)ad {
}
// Ad closed; SDK auto-replenishes
- (void)smartCacheDidHideAd:(MCAdInfo *)ad {
}
// Ad clicked
- (void)smartCacheDidClickAd:(MCAdInfo *)ad {
}
// Ad display failed
- (void)smartCacheDidFailToDisplayAd:(MCAdInfo *)ad withError:(MCError *)error {
}
// Revenue callback
- (void)smartCacheDidPayRevenueForAd:(MCAdInfo *)ad {
}
// Rewarded video exclusive callbacks — not triggered for App Open; implement as empty
- (void)smartCacheDidRewardUserForAd:(MCAdInfo *)ad withReward:(MCReward *)reward { }
- (void)smartCacheDidAdVideoStarted:(MCAdInfo *)ad { }
- (void)smartCacheDidAdVideoCompleted:(MCAdInfo *)ad { }
if ([self.appOpenManager isReady]) {
// window can be nil to use key window; viewController can be nil for top-level VC
[self.appOpenManager showAdWithWindow:nil viewController:self];
}
To pass a scene ID or other extra parameters:
if ([self.appOpenManager isReady]) {
[self.appOpenManager showAdWithWindow:nil
viewController:self
withExtra:@{kMCAPIPlacementScenarioIDKey: @"your scene id"}];
}
[self.appOpenManager destroyAd];
Call
destroyAdwhen the page or module is destroyed to release cache pool resources and avoid memory leaks. After release,loadAdmust be called again to continue using.
- (void)loadAd {
if (!self.appOpenManager) {
self.appOpenManager = [[MCAppOpenAdManager alloc] init];
}
self.appOpenManager.delegate = self;
// (Optional) Set container view
// [self.appOpenManager setAppOpenContainerView:containerView];
// (Optional) Set load timeout in seconds
// [self.appOpenManager setLoadAdTimeout:5.0];
// Set load extra parameters; call before loadAd
[self.appOpenManager setLoadExtraParameter:@{
@"userData": @"test_userData"
}];
// Set mediation extra parameters; call before loadAd
[self.appOpenManager setExtraParameter:@{
@"test_extra_key": @"test_extra_value"
}];
[self.appOpenManager loadAd];
}
| Method | Description |
|---|---|
setAppOpenContainerView: |
Set the App Open ad container view |
setLoadAdTimeout: |
Set load timeout (NSTimeInterval, in seconds; recommended 5-10 seconds) |