💡Tips
- 🚀 Smart Cache automatically manages multi-placement parallel loading and cache comparison — no need to manually manage multiple
MCRewardedAdinstances- ⚠️
MCRewardAdManageris a normal instance class; recommended to hold as a property- 🔧 Use the
smartCacheDidRewardUserForAd:withReward:callback to confirm reward distribution — this is the only reliable reward delivery trigger
#import <MCSDK/MCSDK.h>
@interface SmartCacheRewardedVC () <MCSmartCacheDelegate>
@property (nonatomic, strong) MCRewardAdManager *rewardManager;
@end
@implementation SmartCacheRewardedVC
#pragma mark - Load Ad
- (void)loadAd {
if (!self.rewardManager) {
self.rewardManager = [[MCRewardAdManager alloc] init];
}
// Set delegate before the first loadAd call
self.rewardManager.delegate = self;
[self.rewardManager 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 {
}
// User met reward conditions (the only reliable reward delivery trigger)
- (void)smartCacheDidRewardUserForAd:(MCAdInfo *)ad withReward:(MCReward *)reward {
}
// Video started playing
- (void)smartCacheDidAdVideoStarted:(MCAdInfo *)ad {
}
// Video playback completed
- (void)smartCacheDidAdVideoCompleted:(MCAdInfo *)ad {
}
if ([self.rewardManager isReady]) {
[self.rewardManager showAdWithViewController:self];
}
To pass a scene ID or other extra parameters:
if ([self.rewardManager isReady]) {
[self.rewardManager showAdWithViewController:self
withExtra:@{kMCAPIPlacementScenarioIDKey: @"your scene id"}];
}
Use the MCSmartCacheDelegate callback to confirm reward distribution:
// User met reward conditions
- (void)smartCacheDidRewardUserForAd:(MCAdInfo *)ad withReward:(MCReward *)reward {
// Grant reward here
}
Rewarded video auxiliary callbacks:
// Video started playing
- (void)smartCacheDidAdVideoStarted:(MCAdInfo *)ad { }
// Video playback completed
- (void)smartCacheDidAdVideoCompleted:(MCAdInfo *)ad { }
[self.rewardManager 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.rewardManager) {
self.rewardManager = [[MCRewardAdManager alloc] init];
}
self.rewardManager.delegate = self;
// Set load extra parameters; call before loadAd
[self.rewardManager setLoadExtraParameter:@{
@"userID": @"test_userId",
@"userData": @"test_userData"
}];
// Set mediation extra parameters; call before loadAd
[self.rewardManager setExtraParameter:@{
@"test_extra_key": @"test_extra_value"
}];
[self.rewardManager loadAd];
}