You have already added and configured a custom ad platform in the TopOn backend. If you have not done so yet, please go here.
The following example is a non-bidding ad implementation. For a custom ad platform to implement bidding, please refer here.
Based on the class name you added in the TopOn backend, create the BannerAdapter class (named CustomBannerAdapter in this example).
// CustomBannerAdapter.h
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface CustomBannerAdapter : NSObject
@end
NS_ASSUME_NONNULL_END
// CustomBannerAdapter.m
#import "CustomBannerAdapter.h"
@interface CustomBannerAdapter ()
@end
@implementation CustomBannerAdapter
@end
Make the CustomBannerAdapter class created in the previous step conform to the ATAdAdapter protocol and implement its required methods.
To view more information about the ATAdAdapter protocol, please click here.
#import "CustomBannerAdapter.h"
#import <AnyThinkSDK/AnyThinkSDK.h>
#import <AnyThinkBanner/ATBanner.h>
@interface CustomBannerAdapter() <ATAdAdapter>
@end
@implementation CustomBannerAdapter
/// Must be implemented, used to initialize the custom adapter. Non-bidding ads enter here; for bidding ads, please refer to the documentation.
/// - Parameters:
/// - serverInfo: the parameter dictionary configured on the server
/// - localInfo: the 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 ads
/// - Parameters: implement the logic for the custom ad platform to load ads
/// - serverInfo: the parameter dictionary configured on the server
/// - localInfo: the 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 the ad's validity period)
/// - Parameters:
/// - customObject: the custom ad object
/// - info: the parameter dictionary configured on the server
+ (BOOL)adReadyWithCustomObject:(id)customObject info:(NSDictionary*)info {
BOOL flag = YES;
//Logic for whether the ad is ready
return flag;
}
/// When the TopOn iOS SDK triggers the ad display, this method is called to trigger the ad SDK's ad display logic.
/// - Parameters:
/// - banner: the custom ad banner object
/// - view: the BannerView container defined internally by the TopOn iOS SDK
/// - viewController: the current view controller
+ (void)showBanner:(ATBanner*)banner inView:(UIView*)view presentingViewController:(UIViewController*)viewController {
// Show the ad
}
@end
Implement a custom CustomEvent class (named BannerCustomEvent in this example) that inherits from the ATBannerCustomEvent class. Through this class, add the callback delegates corresponding to the custom ad platform. When the third-party ad platform has a callback, call the event methods you defined in this class. In these event methods you defined, you need to call the methods inherited from ATBannerCustomEvent to pass the events back to the TopOn iOS SDK. This example only demonstrates the ad load-completed callback; add the other methods yourself.
Please click here to view the detailed description of the ATBannerCustomEvent class.
//BannerCustomEvent.h
#import <AnyThinkBanner/AnyThinkBanner.h>
NS_ASSUME_NONNULL_BEGIN
@interface BannerCustomEvent : ATBannerCustomEvent
@end
NS_ASSUME_NONNULL_END
@implementation BannerCustomEvent
/// This is your ad platform SDK's ad load-completed callback. For the specific method name and parameters, please check your ad platform SDK documentation
- (void)your3rdSDKInterstitialAdDidLoad:(id)rewardedVideoAd {
...
//Pass the info back to the TopOn iOS SDK
[self trackBannerAdLoaded:rewardedVideoAd adExtra:nil];
}
...
Other methods that need to be passed back
@end