Menu

Custom Base Adapter

This document is based on the DemoCustomBaseAdapter example code in the Demo, providing detailed instructions on how to create a custom base adapter. The main function of this adapter is to initialize third-party ad platform SDKs and return their version information.

πŸ’‘ Tips

  • Class names can be customized; base adapter and initialization adapter class names do not need to be added to the backend
  • It is recommended to place the base adapter and initialization adapter in the same module for easier management
  • The initialization adapter is responsible for SDK initialization, while the base adapter is responsible for specifying the initialization adapter class name

1. Methods to Override

You need to inherit from ATBaseMediationAdapter and ATBaseInitAdapter and override the relevant methods:

1.1 Required Methods for Initialization Adapter

Method Parameter Description Purpose
- (void)initWithInitArgument:(ATAdInitArgument *)adInitArgument adInitArgument: Contains initialization parameters sent from the server Used to initialize third-party ad platform SDK and set related parameters
- (nullable NSString *)sdkVersion ----- Returns the version number of the ad platform SDK
- (nullable NSString *)adapterVersion ----- Returns the adapter version number

1.2 Required Methods for Base Adapter

Method Parameter Description Purpose
- (Class)initializeClassName ----- Returns the class name of the initialization adapter, used to specify the initialization adapter

Copy
β”œβ”€β”€ Base/                           # Base adapter module
β”‚   β”œβ”€β”€ DemoCustomAdapterCommonHeader.h    # Used to declare common header files
β”‚   β”œβ”€β”€ DemoCustomBaseAdapter.h            # Base adapter header file
β”‚   β”œβ”€β”€ DemoCustomBaseAdapter.m            # Base adapter implementation, defines the initialization adapter class name
β”‚   β”œβ”€β”€ DemoCustomInitAdapter.h            # Initialization adapter header file
β”‚   └── DemoCustomInitAdapter.m            # Initialization adapter implementation

3. Implementation Steps

Step 1: Implement DemoCustomInitAdapter.h

  1. Import header file #import <AnyThinkSDK.h>
  2. Inherit from ATBaseInitAdapter

Example:

objc Copy
#import <Foundation/Foundation.h>
#import "DemoCustomAdapterCommonHeader.h"
 
@interface DemoCustomInitAdapter : ATBaseInitAdapter
  
@end

Step 2: Implement DemoCustomInitAdapter.m

Implement the following methods:

objc Copy
/// Init Ad SDK
/// - Parameter adInitArgument: server info
- (void)initWithInitArgument:(ATAdInitArgument *)adInitArgument{
    // Get backend configuration information from the adInitArgument object, e.g., adInitArgument.serverContentDic[@"appId"]
  // After obtaining the relevant information, call the ad platform SDK's initialization method. You can configure the ad platform SDK as needed, such as privacy settings for overseas platforms (e.g., CCPA, COPPA, GDPR).
  // If the ad platform SDK initialization has a return value, use [self notificationNetworkInitSuccess]; to notify us of successful initialization;
  // If third-party initialization fails, use [self notificationNetworkInitFail:error]; to notify us of initialization failure.
  // If the ad platform SDK initialization has no success or failure callback, you can directly notify us of successful initialization using: [self notificationNetworkInitSuccess];
}

/// Returns the version number of the ad platform SDK
- (nullable NSString *)sdkVersion {
    // Example
    return [YourAdSDK getVersion];
}

/// Returns the adapter version number
- (nullable NSString *)adapterVersion {
    return [YourAdapter getVersion];
}

Step 3: Implement DemoCustomBaseAdapter.h

  1. Import header file #import <AnyThinkSDK.h>
  2. Inherit from ATBaseMediationAdapter

Example:

objc Copy
@interface DemoCustomBaseAdapter : ATBaseMediationAdapter

@end

Step 4: Implement DemoCustomBaseAdapter.m

Implement the following method:

objc Copy
#pragma mark - adapter init class name define
- (Class)initializeClassName {
    // Return the initialization adapter class created in Step 1 of this document
    return [DemoCustomInitAdapter class];
}

4. Additional Settings

4.1 GDPR

Get the data consent level you set through TaKu SDK's -[ATAPI setDataConsentSet:consentString:] method

objc Copy
//typedef NS_ENUM(NSInteger, ATDataConsentSet) {
//    /*
//    This is the default value used when you haven't set one; in this case, if the user is in a GDPR region, SDK initialization will fail,
//    and subsequent ad requests will also fail. This type cannot be set using the setDataConsentSet method
//    */
//    ATDataConsentSetUnknown = 0,
//    /*
//    This level indicates that the user consents to the SDK collecting and using their personal data to provide more relevant and suitable ads.
//    */
//    ATDataConsentSetPersonalized = 1,
//    /*
//    If the data protection level is set to this value, the SDK will not collect user personal data, as the provided ads may not match the user's situation.
//    Additionally, in this case, some data that doesn't involve user privacy may still be collected.
//    */
//    ATDataConsentSetNonpersonalized = 2
//};
// Import header file `#import <AnyThinkSDK.h>`
// Get data consent level
[ATAPI sharedInstance].dataConsentSet

4.2 COPPA

Get the user age you set through Taku SDK
After the developer calls
[ATSDKGlobalSetting sharedManager].customData = @{kATCustomDataAgeKey:@"13",......};
to set the age, you can get the user age set by the developer through
[[ATSDKGlobalSetting sharedManager].customData valueForKey:kATCustomDataAgeKey]

4.3 Personalized Ads

Get the personalized ad state set by the developer through Taku SDK
After the developer calls
[[ATAPI sharedInstance] setPersonalizedAdState:ATPersonalizedAdStateType]
to set the personalized ad state, you can get the personalized ad state set by the developer through
[ATAPI sharedInstance].getPersonalizedAdState

Last modified: 2025-10-10Powered by