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 case is a non-bidding ad implementation. For custom ad platform bidding implementation, please refer here.
Based on the class name you added in the TopOn dashboard, create a NativeAdapter class (named CustomNativeAdapter in this example).
// CustomNativeAdapter.h
#import <foundation>
NS_ASSUME_NONNULL_BEGIN
@interface CustomNativeAdapter : NSObject
@end
NS_ASSUME_NONNULL_END</foundation>
// CustomNativeAdapter.m
#import "CustomNativeAdapter.h"
@interface CustomNativeAdapter ()
@end
@implementation CustomNativeAdapter
@end
Implement a custom CustomEvent class (named NativeCustomEvent in this example) that inherits from the ATNativeCustomEvent class, and use this class to add the callback delegate corresponding to the custom ad platform. When the third-party ad platform triggers 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 ATNativeADCustomEvent to pass the event back to the TopOn iOS SDK. This example only demonstrates the ad load completion callback; add the other methods yourself.
Please click here to view the detailed description of the ATNativeADCustomEvent class.
In this class, you need to map the native ad materials returned by the ad platform to TopOn's corresponding asset dictionary within the callback. Please go to the CustomEvent Mapping section.
//NativeCustomEvent.h
#import <anythinknative>
NS_ASSUME_NONNULL_BEGIN
@interface NativeCustomEvent : ATNativeADCustomEvent
@end
NS_ASSUME_NONNULL_END</anythinknative>
@implementation NativeCustomEvent
/// This is the ad load completion callback of your ad platform SDK. For the specific method name and parameters, refer to your ad platform SDK documentation.
- (void)your3rdSDKInterstitialAdDidLoad:(id)rewardedVideoAd {
...
//Pass the information back to the TopOn iOS SDK
[self trackBannerAdLoaded:rewardedVideoAd adExtra:nil];
}
...
Other methods that need to be passed back
@end
The TopOn iOS SDK provides an internal wrapper for native ad rendering. Therefore, when implementing a custom native ad Adapter, you need to implement a Renderer class (YourCustomNativeRenderer in this example) to map the native parameters returned by the ad platform to TopOn's internal objects.
Please click here to view the detailed description of the ATNativeRenderer class.
Please click here to view the detailed description of the ATNativeADRenderer protocol.
You may use image download related methods. Go to Image Download API to view them.
#import <foundation>
#import <anythinknative>
NS_ASSUME_NONNULL_BEGIN
@interface YourCustomNativeRenderer : ATNativeRenderer
@end
NS_ASSUME_NONNULL_END</anythinknative></foundation>
#import "YourCustomNativeRenderer.h"
#import "NativeCustomEvent.h"
#import <anythinknative>
@interface YourCustomNativeRenderer()
@property (nonatomic, weak) NativeCustomEvent * customEvent;
@end
@implementation YourCustomNativeRenderer
/// Render the assets onto the relevant ad views.
/// Based on the requirements of the ad platform, you can register click events after rendering.
- (void)renderOffer:(ATNativeADCache *)offer {
...
}
/// If the ad format contains a MediaView, you need to implement createMediaView to return the mediaview object to the TopOn iOS SDK.
- (__kindof UIView*)getNetWorkMediaView {
return yourMeidaView;
}
@end</anythinknative>
Make the CustomNativeAdapter class created in the first step conform to the ATAdAdapter protocol and implement its required methods.
For more information about the ATAdAdapter protocol, please click here.
#import "CustomNativeAdapter.h"
#import <anythinksdk>
@interface CustomNativeAdapter() <atadadapter>
@end
@implementation CustomNativeAdapter
/// Used to return the custom Renderer class.
+ (Class)rendererClass {
return [YourRendererClass class];
}
/// Must be implemented. Used to initialize the custom adapter. Entered by non-bidding ads; for bidding ads, 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: The completion callback.
- (void)loadADWithInfo:(NSDictionary*)serverInfo localInfo:(NSDictionary*)localInfo completion:(void (^)(NSArray<nsdictionary> *, NSError *))completion {
// Load the ad
}
@end</nsdictionary></atadadapter></anythinksdk>