You have already added and configured a custom ad platform in the TopOn dashboard. If you have not done so yet, please go here.
The following example is a non-bidding ad implementation. For bidding with a custom ad platform, please refer here.
Based on the class name you added in the TopOn dashboard, create the InterstitialAdapter class (named CustomInterstitialAdapter in this example).
// CustomInterstitialAdapter.h
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface CustomInterstitialAdapter : NSObject
@end
NS_ASSUME_NONNULL_END
// CustomInterstitialAdapter.m
#import "CustomInterstitialAdapter.h"
@interface CustomInterstitialAdapter ()
@end
@implementation CustomInterstitialAdapter
@end
Make the CustomInterstitialAdapter class created in the previous step conform to the ATAdAdapter protocol and implement its required methods.
To see more information about the ATAdAdapter protocol, please click here.
#import "CustomInterstitialAdapter.h"
#import <AnyThinkSDK/AnyThinkSDK.h>
#import <AnyThinkInterstitial/ATInterstitial.h>
@interface CustomInterstitialAdapter() <ATAdAdapter>
@end
@implementation CustomInterstitialAdapter
/// Must be implemented. Used to initialize the custom adapter. Entered for non-bidding ads; for bidding ads please refer to the documentation.
/// - Parameters:
/// - serverInfo: Parameter dictionary configured on the server
/// - localInfo: Parameter dictionary passed in for this load
- (instancetype)initWithNetworkCustomInfo:(NSDictionary*)serverInfo localInfo:(NSDictionary*)localInfo {
self = [super init];
if (self != nil) {
// Add your ad SDK initialization method here
}
return self;
}
/// Must be implemented. The logic for the custom ad platform to load an ad.
/// - Parameters: Implement the logic for the custom ad platform to load an ad
/// - serverInfo: Parameter dictionary configured on the server
/// - localInfo: Parameter dictionary passed in for this load
/// - completion: Completion callback
- (void)loadADWithInfo:(NSDictionary*)serverInfo localInfo:(NSDictionary*)localInfo completion:(void (^)(NSArray<NSDictionary *> *, NSError *))completion {
// Load the ad
}
/// Must be implemented. Used to determine whether the custom ad platform's ad is ready (or within its valid period).
/// - Parameters:
/// - customObject: Custom ad object
/// - info: Parameter dictionary configured on the server
+ (BOOL)adReadyWithCustomObject:(id)customObject info:(NSDictionary*)info {
BOOL flag = //Logic for whether the ad is ready
return flag;
}
/// Implement the logic for showing the custom ad platform's interstitial.
/// - Parameters:
/// - interstitial: Interstitial ad object
/// - viewController: Current view controller
/// - delegate: Ad object delegate
+ (void)showInterstitial:(ATInterstitial *)interstitial inViewController:(UIViewController*)viewController delegate:(id)delegate {
// Show the ad
}
@end
Implement a custom CustomEvent class (named InterstitialCustomEvent in this example) that inherits from the ATInterstitialCustomEvent class. Through this class, add the callback delegate corresponding to the custom ad platform. When the third-party ad platform has a callback, call the event method you defined in this class. In this event method you defined, you need to call the method inherited from ATInterstitialCustomEvent to pass the event back to the TopOn iOS SDK. This example only illustrates the ad load completion callback; other methods are to be added by yourself.
Please click here to view the detailed description of the ATInterstitialCustomEvent class.
When implementing the interstitial ad callback events for the custom ad platform, if there are no video playback and completion related callback events, you may omit them.
//InterstitialCustomEvent.h
#import <AnyThinkInterstitial/AnyThinkInterstitial.h>
NS_ASSUME_NONNULL_BEGIN
@interface InterstitialCustomEvent : ATInterstitialCustomEvent
@end
NS_ASSUME_NONNULL_END
@implementation InterstitialCustomEvent
/// This is the ad load completion callback of your ad platform SDK. For the specific method name and parameters, please refer to your ad platform SDK documentation
- (void)your3rdSDKInterstitialAdDidLoad:(id)rewardedVideoAd {
...
//Pass the information back to the TopOn iOS SDK
[self trackInterstitialAdLoaded:rewardedVideoAd adExtra:nil];
}
...
Other methods that need to be passed back
@end