Native
1. Methods that need to be rewritten
- Developers need to inherit TradPlusBaseAdapter and rewrite related methods:
- When developers call the
loadAdAPI ofTradPlusAdNative, theloadAdWithWaterfallItem:method of the custom Adapter will be called. - When developers call the
isAdReadyAPI ofTradPlusAdNative, theisReadymethod of the custom Adapter will be called
- When developers call the
- When developers call
showADWithRenderingViewClass:subview:sceneId:orshowADWithNativeRenderer:subview:sceneId:API ofTradPlusAdNative, theisReadyandendRender:clickView:(self-rendering type) methods of the custom Adapter will be called in sequence
| Method | Parameter Description | Return Value | Function |
|---|---|---|---|
| - (void)loadAdWithWaterfallItem:(TradPlusAdWaterfallItem *)item | item: Contains parameters sent by the server and locally configured | void | Used to obtain the parameters sent by the server and locally configured to implement the loading logic of custom ads |
| - (UIView *)endRender:(NSDictionary *)viewInfo clickView:(NSArray *)array | viewInfo: rendering component dictionary list clickView: clickable view array | id | Used for self-rendering type native ads registration components, click events, etc. |
| - (BOOL)isReady | ----- | Bool | Used to determine whether a custom ad is expired before displaying the ad |
2.Callback method description
| Method | Description |
|---|---|
| - (void)AdConfigError | Ad configuration information is wrong |
| - (void)AdLoadFinsh | Ad loading is complete |
| - (void)AdLoadFailWithError:(NSError *)error | Ad loading fails error: error message |
| - (void)AdShow | Ad is displayed |
| - (void)AdShowFailWithError:(NSError *)error | Ad display fails error: error message |
| - (void)AdClick | Ad is clicked |
| - (void)AdClose | Ad is closed |
3. Integration Instructions
- Create a custom class that you registered in the TradPlus background and inherit TradPlusBaseAdapter
#import <TradPlusAds/TradPlusBaseAdapter.h>
@interface ClassName : TradPlusBaseAdapter
@end
- Implement the initialization, loading and other logic of the custom platform in the
loadAdWithWaterfallItem:method
-
Get the background configuration parameters through the
TradPlusAdWaterfallItemclass,item.config -
Initialize a custom advertising platform, set the advertising platform parameters and overseas platform privacy settings (such as CCPA, COPPA, GDPR) according to your own needs.
//example
- (void)loadAdWithWaterfallItem:(TradPlusAdWaterfallItem *)item
{
//Get background configuration information through item.config
NSString *placementId = item.config[@"placementId"];
if(placementId == nil)
{
//Configuration Error
[self AdConfigError]
return;
}
//Initialize third-party platforms, set parameters for advertising platforms, privacy settings for overseas platforms, etc.
GADRequest *request = [GADRequest request];
//Setting up GDPR
if (![MSConsentManager sharedManager].canCollectPersonalInfo)
{
GADExtras *extras = [[GADExtras alloc] init];
extras.additionalParameters = @{@"npa": @"1"};
[request registerAdNetworkExtras:extras];
}
//Set other parameters
GADNativeAdImageAdLoaderOptions *nativeAdImageLoaderOptions =
[[GADNativeAdImageAdLoaderOptions alloc] init];
nativeAdImageLoaderOptions.shouldRequestMultipleImages = NO;
GADNativeAdMediaAdLoaderOptions *nativeAdMediaAdLoaderOptions =
[[GADNativeAdMediaAdLoaderOptions alloc] init];
nativeAdMediaAdLoaderOptions.mediaAspectRatio = GADMediaAspectRatioAny;
GADNativeAdViewAdOptions *nativeAdViewAdOptions = [[GADNativeAdViewAdOptions alloc] init];
nativeAdViewAdOptions.preferredAdChoicesPosition = GADAdChoicesPositionTopRightCorner;
self.adLoader =
[[GADAdLoader alloc] initWithAdUnitID:placementId
rootViewController:nil
adTypes:@[ kGADAdLoaderAdTypeNative ]
options:@[ nativeAdImageLoaderOptions,
nativeAdViewAdOptions,
nativeAdMediaAdLoaderOptions
]];
self.adLoader.delegate = self;
[self.adLoader loadRequest:request];
}
- Call
AdLoadFailWithError:orAdLoadFinshaccording to the load result
- Loading failed
//example
#pragma mark - GADAdLoaderDelegate
- (void)adLoader:(nonnull GADAdLoader *)adLoader
didFailToReceiveAdWithError:(nonnull NSError *)error
{
//Loading failed
[self AdLoadFailWithError:error];
}
- Loading successful (self-rendering type)
- Create
TradPlusAdResafter successful loading - Bind the elements or third-party controls in the self-rendering material to the fields in
TradPlusAdResaccording to platform requirements - Bind
TradPlusAdRestoself.waterfallItem.adRes - Call
AdLoadFinshto complete the loading process
- Create
//example
#pragma mark - GADNativeAdLoaderDelegate
- (void)adLoader:(nonnull GADAdLoader *)adLoader didReceiveNativeAd:(nonnull GADNativeAd *)nativeAd
{
self.nativeAd = nativeAd;
self.nativeAd.delegate = self;
//Create a new TradPlusAdRes
TradPlusAdRes *res = [[TradPlusAdRes alloc] init];
// Bind elements
res.title = self.nativeAd.headline;
res.body = self.nativeAd.body;
res.ctaText = self.nativeAd.callToAction;
if(self.nativeAd.icon != nil)
{
res.iconImage = self.nativeAd.icon.image;
}
self.mediaView = [[GADMediaView alloc] init];
self.mediaView.mediaContent = self.nativeAd.mediaContent;
res.mediaView = self.mediaView;
//Set Res. Used for native interface rendering
self.waterfallItem.adRes = res;
// Loading successfully
[self AdLoadFinsh];
}
- Loading Successfully (Template Type)
- Create
TradPlusAdResafter loading successfully - Bind the adView of
TradPlusAdResto the returned third-party template view - Bind
TradPlusAdRestoself.waterfallItem.adRes - Call
AdLoadFinshto complete the loading process
- Create
//example
#pragma mark - MTGNativeAdvancedAdDelegate
- (void)nativeAdvancedAdLoadSuccess:(MTGNativeAdvancedAd *)nativeAd
{
//Create a new TradPlusAdRes
TradPlusAdRes *res = [[TradPlusAdRes alloc] init];
self.adView = [self.advancedAd fetchAdView];
//Set the template view
res.adView = self.adView;
//Set Res
self.waterfallItem.adRes = res;
// Loading successfully
[self AdLoadFinsh];
}
- For self-rendering type, you need to register the rendering element in the
endRender:clickView:method
-
Register each element according to the third-party platform rules
-
Template types do not need to implement this method
Example 1: According to AdMob's rules, AdMob's GADNativeAdView needs to be used to register and display the ad view.
//example
- (UIView *)endRender:(NSDictionary *)viewInfo clickView:(NSArray *)array
{
GADNativeAdView *nativeAdView = [[GADNativeAdView alloc] init];
nativeAdView.nativeAd = self.nativeAd;
if([viewInfo valueForKey:kTPRendererAdView])
{
UIView *view = viewInfo[kTPRendererAdView];
nativeAdView.frame = view.bounds;
[nativeAdView addSubview:view];
}
if([viewInfo valueForKey:kTPRendererTitleLable])
{
UIView *view = viewInfo[kTPRendererTitleLable];
nativeAdView.headlineView = view;
}
if([viewInfo valueForKey:kTPRendererTextLable])
{
UIView *view = viewInfo[kTPRendererTextLable];
nativeAdView.bodyView = view;
}
if([viewInfo valueForKey:kTPRendererCtaLabel])
{
UIView *view = viewInfo[kTPRendererCtaLabel];
nativeAdView.callToActionView = view;
}
if([viewInfo valueForKey:kTPRendererIconView])
{
UIView *view = viewInfo[kTPRendererIconView];
nativeAdView.iconView = view;
}
if(self.mediaView != nil)
{
nativeAdView.mediaView = self.mediaView;
}
//Complete the setup and return to AdMob's GADNativeAdView
return nativeAdView;
}
Example 2: Facebook According to Facebook's rules, you only need to register the ad view and clickable view with it.
//example
- (UIView *)endRender:(NSDictionary *)viewInfo clickView:(NSArray *)array
{
UIView *adView = viewInfo[kTPRendererAdView];
[self.nativeAd registerViewForInteraction:adView
mediaView:self.mediaView
iconView:self.iconView
viewController:self.rootViewController
clickableViews:array];
//Complete the registration operation and return nil
return nil;
}
- Description of commonly used key values in ViewInfo
| key | Description |
|---|---|
| kTPRendererAdView | Ad view |
| kTPRendererTitleLable | Ad title |
| kTPRendererTextLable | Ad description |
| kTPRendererCtaLabel | Ad button |
| kTPRendererIconView | Ad icon |
| kTPRendererMainImageView | Ad main image |
| kTPRendererMediaView | MediaView |
| kTPRendererAdChoiceImageView | AdChoice icon |
- Return whether the ad is expired in the
isReadymethod
//example
- (BOOL)isReady
{
return (self.nativeAd != nil);
}
- According to the API of each advertising platform, execute relevant methods to notify developers
//example
#pragma mark - GADNativeAdDelegate
- (void)nativeAdDidRecordImpression:(nonnull GADNativeAd *)nativeAd;
{
//Ad display
[self AdShow];
}
- (void)nativeAdDidRecordClick:(nonnull GADNativeAd *)nativeAd
{
//Ad click
[self AdClick];
}
4.Others
How to obtain the overseas privacy permission setting parameters in TradPlusSDK
#import <TradPlusAds/MsCommon.h>
#import <TradPlusAds/MSConsentManager.h>
| Method | Description |
|---|---|
| [[NSUserDefaults standardUserDefaults] integerForKey:gTPCOPPAStorageKey] | COPPA, Children's Online Privacy Protection Act 0=not set, 1=adult, 2=child |
| [[NSUserDefaults standardUserDefaults] integerForKey:gTPCCPAStorageKey] | CCPA, California Consumer Privacy Act 0=not set, 1=do not report data, 2=report data |
| [MSConsentManager sharedManager].canCollectPersonalInfo | GDPR, General Data Protection Regulation of the European Union (EU) and the European Economic Area (EEA) yes=allow access to device data no=do not allow access to device data |