Search...
Menu

Customized Mediation Adapter

Please refer to the guide on how to set up a custom mediation platform in the TopOn Dashboard

1. Using Custom Aggregation Platform

(1) You only need to extend MCMediationAdapter and implement the corresponding methods in the MCMediationAdapterProtocol. All methods in the custom aggregation platform adapter do not require your invocation. The MCSDK will call the relevant methods in the custom aggregation platform adapter at the appropriate time.

(2) The ad delegate callback of the custom aggregation platform needs to notify the MCSDK by calling the corresponding delegate method through the adDelegate object of MCMediationAdapter. The MCSDK will then callback to the external MCAdDelegate user after receiving the notification from the previous step.

  • MCMediationAdapterProtocol

    Method Description
    - (void)initSDK:(MCMediationInfo *_Nonnull)mediationInfo completed:(nullable MCAdapterInitCompletionBlock)completedBlock; Method for initializing the SDK of the custom aggregation platform.
    - (void)setLogDebug:(BOOL)isLogDebug; Debug log switch for the custom aggregation platform.
    - (void)loadRewardedAd:(MCLoadInfo *_Nonnull)loadInfo delegate:(id<MCAdapterDelegate>_Nonnull)delegate; Method for loading rewarded video ads in the custom aggregation platform.
    - (void)loadInterstitialAd:(MCLoadInfo *_Nonnull)loadInfo delegate:(id<MCAdapterDelegate>_Nonnull)delegate; Method for loading interstitial ads in the custom aggregation platform.
    - (void)loadAdViewAd:(MCLoadInfo *_Nonnull)loadInfo delegate:(id<MCAdapterDelegate>_Nonnull)delegate; Method for loading banner ads in the custom aggregation platform.
    - (void)loadAppOpenAd:(MCLoadInfo *_Nonnull)loadInfo containerView:(UIView *_Nullable)containerView delegate:(id<MCAdapterDelegate>_Nonnull)delegate; Method for loading app open ads in the custom aggregation platform.
    - (void)loadNative:(MCLoadInfo *_Nonnull)loadInfo delegate:(id<MCAdapterDelegate>_Nonnull)delegate; Method for loading native ads in the custom aggregation platform.
    - (void)show:(UIViewController *_Nullable)vc extra:(NSDictionary *_Nullable)extra; Method for displaying interstitial and rewarded video ads in the custom aggregation platform.
    - (void)showAdWithWindow:(UIWindow *_Nullable)window viewController:(UIViewController *_Nullable)viewController withExtra:(NSDictionary *_Nullable)extra; Method for displaying app open ads in the custom aggregation platform.
    - (UIView *_Nullable)getBannerView; Method for obtaining the BannerView in the custom aggregation platform.
    - (BOOL)isAdReady; Method for determining whether the ad is ready to be displayed in the custom aggregation platform.
    - (void)destroyAd; Method for releasing resources in the custom aggregation platform.

3. Aggregation Platform Information Object

  • MCMediationInfo

    Property Description
    @property (nonatomic, assign) NSInteger mediationId; Gets the ID value of the aggregation platform.
    @property (nonatomic, strong) NSDictionary *mediationInitParams; Gets the map of initialization information, used to obtain parameters such as appId and appKey from this map when initializing the aggregation platform.
    @property (nonatomic, strong) NSString *mediationAdapterClass; Gets the class of the aggregation platform adapter.

4. Ad Loading Information Object

  • MCLoadInfo

    Property Description
    @property (nonatomic, strong) NSDictionary *loadExtraParameter; Used by the aggregation platform SDK to obtain additional information map during loading. Each aggregation platform can pass unique parameters.
    @property (nonatomic, copy) NSString *placementId; The ad placement ID of the aggregation platform.
    @property (nonatomic, assign) double weight; The weight value of the aggregation platform.
    @property (nonatomic, copy) NSDictionary<NSString *, NSString *> *content; Configuration parameters of the aggregation platform.
    @property (nonatomic, assign) NSTimeInterval loadAdTimeoutInterval; The ad loading timeout interval of the aggregation platform.
    @property (nonatomic, strong) NSString *requestId; The request ID for the current request.

5. Ad Loading Event Callback

  • MCAdDelegate

    Method Description
    - (void)didAdLoadSuccess:(MCIAdInfo *)ad; Called when the ad is successfully loaded to notify the MCSDK (used only for rewarded, interstitial, banner, and app open ads).
    - (void)didAdLoadSuccess:(MCIAdInfo *)ad withNativeAd:(MCNativeAd *)nativeAd; Called when the ad is successfully loaded to notify the MCSDK (used only for native ads).
    - (void)didFailToLoadAdWithError:(MCError *)error; Called when the ad fails to load to notify the MCSDK.
    - (void)didAdShow:(MCIAdInfo *)ad; Called when the ad is successfully displayed to notify the MCSDK.
    - (void)didAdClick:(MCIAdInfo *)ad; Called when the ad is clicked to notify the MCSDK.
    - (void)didAdClose:(MCIAdInfo *)ad; Called when the ad is closed to notify the MCSDK.
    - (void)didAdVideoStart:(MCIAdInfo *)ad; Called when the ad video starts playing to notify the MCSDK.
    - (void)didAdVideoEnd:(MCIAdInfo *)ad; Called when the ad video ends playing to notify the MCSDK.
    - (void)didAdDisplayFailed:(MCIAdInfo *)ad withError:(MCAdapterError *)error; Called when the ad display fails to notify the MCSDK.
    - (void)didAdRewardSuccess:(MCIAdInfo *)ad withReward:(MCReward *)rewardInfo; Called when the rewarded video ad triggers a reward to notify the MCSDK.
    - (void)didAdRevenuePaid:(MCIAdInfo *)ad; Called when ad revenue is obtained to notify the MCSDK.

6. Ad Loading Result Object

  • MCIAdInfo

    💡Tips: You need to refer to the method description below, inherit IAdInfo, and construct the ad loading result object yourself.

    Property Return Type Description
    mediationId NSInteger Gets the ID corresponding to the aggregation platform, used to distinguish the aggregation platform.
    mediationPlacementId NSString * Gets the ad placement ID of the aggregation platform.
    networkName NSString * Gets the name of the ad source.
    networkPlacementId NSString * Gets the ad placement ID of the ad platform.
    revenue double` Gets the revenue, i.e., the revenue for each ad display.
    revenuePrecision RevenuePrecisionEnum` Gets the revenue precision.
    currency NSString * Gets the currency unit of the revenue.
    country NSString * Gets the country code.
    format MCAdFormat` Gets the ad type.
    scenarioId NSString * Gets the ad scenario ID.
    extraDic NSDictionary * Gets the additional information of the aggregation platform ad.
    originData NSString * Gets the original information of the aggregation platform ad callback.

7. Sample Code

Copy
<code class="language-objective-c">#import &quot;MCMediationAdapter.h&quot;

NS_ASSUME_NONNULL_BEGIN

@interface YourCustomMCMediationAdapter : MCMediationAdapter

@end

NS_ASSUME_NONNULL_END
#import &quot;YourCustomMCMediationAdapter.h&quot;
#import &lt;ImportYourCustomAggregationSDKHeaderFile&gt;
#import &quot;MCIAdInfo+Internal.h&quot;
#import &quot;MCGroMoreNativeAd.h&quot;

#import &lt;objc/message.h&gt;
#import &lt;objc/runtime.h&gt;

#define kMCAPIAppIDKey @&quot;app_id&quot;
#define kMCAPICurrencyKey @&quot;currency&quot;

static MCAdapterInitStatus initStatus = MCAdapterInitNo;

@interface YourCustomMCMediationAdapter () &lt;CustomAggregationSDKAdTypeDelegate&gt;

@property (nonatomic, strong) CustomAggregationSDKRewardedVideoClass *rewardedVideoAd;
@property (nonatomic, strong) CustomAggregationSDKInterstitialClass *interstitialAd;
@property (nonatomic, strong) CustomAggregationSDKSplashClass *splashAd;
@property (nonatomic, strong) CustomAggregationSDKBannerClass *bannerView;
@property (nonatomic, strong) CustomAggregationSDKNativeClass *nativeAd;

@property (nonatomic, assign) BOOL isDidAdShowCallback;
@property (nonatomic, assign) BOOL isDidAdVideoStartCallback;

@property (nonatomic, copy) NSString *currency;

@end

@implementation YourCustomMCMediationAdapter

- (void)dealloc
{
    
}

- (NSString *)mediationVersion {
    return CustomAggregationSDKVersion
}

static NSString *_advanceSDKConfigPath = nil;
+ (void)setAdvanceSDKConfigPath:(NSString *)advanceSDKConfigPath {
    _advanceSDKConfigPath = [advanceSDKConfigPath copy];
}
+ (NSString *)advanceSDKConfigPath {
    return _advanceSDKConfigPath;
}

#pragma mark - MCMediationAdapterProtocol

- (void)initSDK:(MCMediationInfo *_Nonnull)mediationInfo completed:(nullable MCAdapterInitCompletionBlock)completedBlock {
    [super initSDK:mediationInfo completed:completedBlock];
    
    NSDictionary *mediationInitParams = mediationInfo.mediationInitParams;
    NSString *appIDKey = mediationInitParams[kMCAPIAppIDKey];
    self.currency = mediationInitParams[kMCAPICurrencyKey] ?: @&quot;USD&quot;;
    
    if (initStatus != MCAdapterInitNo) {
        if (completedBlock) {
            completedBlock(initStatus, nil);
        }
        return;
    }
    initStatus = MCAdapterInitializing;
    
    if (!appIDKey.length) {
        NSError *error = [[NSError alloc] initWithDomain:@&quot;parameter error&quot; code:0 userInfo:@{}];
        initStatus = MCAdapterInitFailed;
        if (completedBlock) {
            completedBlock(initStatus, error);
        }
        return;
    }
    
    // Configure and initialize the custom aggregation SDK here
    ......
}

- (void)loadRewardedAd:(MCLoadInfo *_Nonnull)loadInfo delegate:(id&lt;MCAdapterDelegate&gt;_Nonnull)delegate {
    [super loadRewardedAd:loadInfo delegate:delegate];
    
    // Use the custom aggregation SDK to load rewarded video ads
    ......
    self.rewardedVideoAd = xxx
    ......
}

- (void)loadInterstitialAd:(MCLoadInfo *_Nonnull)loadInfo delegate:(id&lt;MCAdapterDelegate&gt;_Nonnull)delegate {
    [super loadInterstitialAd:loadInfo delegate:delegate];
    
    // Use the custom aggregation SDK to load interstitial ads
    ......
    self.interstitialAd = xxx
    ......
}

- (void)loadAppOpenAd:(MCLoadInfo *_Nonnull)loadInfo containerView:(UIView *_Nullable)containerView delegate:(id&lt;MCAdapterDelegate&gt;_Nonnull)delegate {
    [super loadAppOpenAd:loadInfo containerView:containerView delegate:delegate];
    
    // Use the custom aggregation SDK to load splash ads
    ......
    self.splashAd = xxx
    ......
}

// banner
- (void)loadAdViewAd:(MCLoadInfo *_Nonnull)loadInfo delegate:(id&lt;MCAdapterDelegate&gt;_Nonnull)delegate {
    [super loadAdViewAd:loadInfo delegate:delegate];
    
    // Use the custom aggregation SDK to load banner ads
    ......
    self.bannerView = xxx
    ......
}

// native
- (void)loadNative:(MCLoadInfo *_Nonnull)loadInfo delegate:(id&lt;MCAdapterDelegate&gt;_Nonnull)delegate {
    [super loadNative:loadInfo delegate:delegate];
    
    // Set some callback flags as needed
    self.isDidAdShowCallback = NO;
    self.isDidAdVideoStartCallback = NO;
    
    // Use the custom aggregation SDK to load native ads
    ......
    self.bannerView = xxx
    ......
}

// Return whether the ad is ready
- (BOOL)isAdReady {
    if (self.format == [MCAdFormat rewarded]) {
        return self.rewardedVideoAd.isReady;
    }
    if (self.format == [MCAdFormat interstitial]) {
        return self.interstitialAd.isReady;
    }
    if (self.format == [MCAdFormat appOpen]) {
        return self.splashAd.isReady;
    }
    if ([self.format isAdViewAd]) {
        return self.bannerView.isReady;
    }
    if (self.format == [MCAdFormat native]) {
        return self.nativeAd.isReady;
    }
    return NO;
}

// Show interstitial and rewarded video
- (void)show:(UIViewController *_Nullable)vc extra:(NSDictionary *_Nullable)extra {
    [super show:vc extra:extra];
    if (self.format == [MCAdFormat rewarded]) {
        [self.rewardedVideoAd show...
    } else if (self.format == [MCAdFormat interstitial]) {
        [self.interstitialAd show...
    }
}

// Show splash ad
- (void)showAdWithWindow:(UIWindow *_Nullable)window viewController:(UIViewController *_Nullable)viewController withExtra:(NSDictionary *_Nullable)extra {
    [super showAdWithWindow:window viewController:viewController withExtra:extra];
    
    if (self.format == [MCAdFormat appOpen]) {
        [self.splashAd show...
    }
}

// Show mediation debugger
- (void)showMediationDebuggerWithViewController:(UIViewController * _Nullable)viewController {
    // Show third-party aggregation debugging tool
}

// Get banner view
- (UIView *_Nullable)getBannerView {
    return self.bannerView;
}

- (void)destroyAd {
    if ([self.format isAdViewAd]) {
        // Destroy resources
        [self.bannerView destory];
        self.bannerView = nil;
    } else if (self.format == [MCAdFormat native]) {
        // Destroy resources
        [self.nativeAd destory];
        self.nativeAd = nil;
    }
}

#pragma mark - Overwrite

- (void)initAdInfo {
    [super initAdInfo];
    
    self.adInfo.networkPlacementId = self.ritInfo.slotID;

    [self updateRevenue:self.ritInfo];
    self.adInfo.compareRevenue = self.adInfo.originRevenue;
    if (self.adInfo.originRevenue &lt;= 0) {
        self.adInfo.compareRevenue = [self getGroMorePrice];
    }
    
    [self showLog:[NSString stringWithFormat:@&quot;gromore offer ecpm:%@&quot;, [NSNumber numberWithDouble:self.adInfo.originRevenue*1000]]];
    
    self.adInfo.revenuePrecision = ({
        RevenuePrecisionEnum revenuePrecision = RuePsionUndefined;
        revenuePrecision = CustomAggregationProvidedInterface
        revenuePrecision;
    });
    
    self.adInfo.country = @&quot;&quot;;
    self.adInfo.currency = self.currency;
    self.adInfo.networkName = self.ritInfo.adnName;
    self.adInfo.extraDic = nil;
    
    [self updateOriginData:self.mediaExt];
}

#pragma mark - Implement custom aggregation platform event protocol methods, and notify MCSDK through adDelegate, take splash as an example, you can prepare some information to set to adInfo before notification
- (void)splashAdDidShowFailed:(SplashAd *_Nonnull)splashAd error:(NSError *)error {
    [self showDelegateLog:[NSString stringWithFormat:@&quot;splashAdDidShowFailed:error: %@, %@&quot;, splashAd, error]];
    
    MCAdapterError *mcError = [[MCAdapterError alloc] initWithCode:error.code message:error.description mediationId:self.mediationId mediatedNetworkErrorCode:error.code mediatedNetworkErrorMessage:error.description originError:error];
    [self.adDelegate didAdDisplayFailed:self.adInfo withError:mcError];
}

- (void)splashAdLoadSuccess:(SplashAd *)splashAd {
    self.ritInfo = [splashAd.mediation getCurrentBestEcpmInfo];
    self.mediaExt = splashAd.mediaExt;
    [self initAdInfo];
    
    [self showDelegateLog:[NSString stringWithFormat:@&quot;splashAdLoadSuccess: %@&quot;, splashAd]];
    [self.adDelegate didAdLoadSuccess:self.adInfo];
}

.... Other ad types are similar

@end
</code>
Previous
SDK Preset Strategy
Next
Revenue Tracking
Last modified: 2025-03-17Powered by