Skip to main content

Banner

1. Methods that need to be rewritten

  • Developers need to inherit TradPlusBaseAdapter and rewrite related methods:
    • When developers call the loadAdWithSceneId: API of TradPlusAdBanner, the loadAdWithWaterfallItem: method of the custom Adapter will be called.
    • When developers call the isAdReady API of TradPlusAdBanner, the isReady method of the custom Adapter will be called
    • When developers call the showWithSceneId: API of TradPlusAdBanner, the isReady and getCustomObject methods of the custom Adapter will be called in sequence.
    • In the default automatic display mode of TradPlusAdBanner, the SDK will automatically call showWithSceneId after loading is completed.
MethodParameter DescriptionReturn ValueFunction
- (void)loadAdWithWaterfallItem:(TradPlusAdWaterfallItem *)itemitem: Contains parameters sent by the server and locally configuredvoidUsed to obtain the parameters sent by the server and locally configured to implement the loading logic of custom ads
- (id)getCustomObjectReturns the banner ad instance displayed when show AdidUsed to return the banner ad instance after loading is completed
- (BOOL)isReady-----BoolBool

2.Callback method description

MethodDescription
- (void)AdConfigErrorAd configuration information is wrong
- (void)AdLoadFinshAd loading is complete
- (void)AdLoadFailWithError:(NSError *)errorAd loading fails
error: error message
- (void)AdShowAd is displayed
- (void)AdShowFailWithError:(NSError *)errorAd display fails
error: error message
- (void)AdClickAd is clicked
- (void)AdCloseAd is closed

3. Integration Instructions

  1. Create a custom class that you registered in the TradPlus background and inherit TradPlusBaseAdapter
#import <TradPlusAds/TradPlusBaseAdapter.h>
@interface ClassName : TradPlusBaseAdapter

@end
  1. Implement the initialization, loading and other logic of the custom platform in the loadAdWithWaterfallItem: method
  • Get the background configuration parameters through the TradPlusAdWaterfallItem class, item.config

  • Through the TradPlusAdWaterfallItem class, item.bannerRootViewController gets the UIViewController used to display content after user interaction

  • 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.

  • Load the ad; after loading, call AdLoadFinsh or AdLoadFailWithError to notify whether the loading is successful or not

//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.
// Set the banner size
GADAdSize adSize = kGADAdSizeBanner;
self.bannerView = [[GADBannerView alloc] initWithAdSize:adSize];
self.bannerView.adUnitID = placementId;
self.bannerView.rootViewController = item.bannerRootViewController;
self.bannerView.delegate = self;
GADRequest *request = [GADRequest request];
//Setting up GDPR
if (![MSConsentManager sharedManager].canCollectPersonalInfo)
{
GADExtras *extras = [[GADExtras alloc] init];
extras.additionalParameters = @{@"npa": @"1"};
[request registerAdNetworkExtras:extras];
}
[self.bannerView loadRequest:request];
}

#pragma mark - GADBannerViewDelegate
- (void)bannerViewDidReceiveAd:(nonnull GADBannerView *)bannerView
{
//Loading Successfully
[self AdLoadFinsh];
}

- (void)bannerView:(nonnull GADBannerView *)bannerView
didFailToReceiveAdWithError:(nonnull NSError *)error
{
//Loading failed
[self AdLoadFailWithError:error];
}
  1. Return the banner ad instance for display in the getCustomObject method
//example
- (id)getCustomObject
{
return self.bannerView;
}
  1. Implement the display of the custom platform in the showAdFromRootViewController: method
//example
- (BOOL)isReady
{
return (self.bannerView != nil);
}
  1. According to the API of each advertising platform, execute relevant methods to notify developers
//example
- (void)bannerViewDidRecordImpression:(nonnull GADBannerView *)bannerView
{
//Ad display
[self AdShow];
}

- (void)bannerViewDidRecordClick:(nonnull GADBannerView *)bannerView
{
//Ad click
[self AdClick];
}

4.Others

Code Sample

Optional API bannerDidAddSubView:

This method is called when the banner ad is added to the screen.

Please adjust according to the characteristics of the third-party platform, such as: adjust the width, center, etc.

//example
- (void)bannerDidAddSubView:(UIView *)subView
{
if(subView.bounds.size.width != 0)
{
CGRect rect = self.bannerView.frame;
rect.size.width = subView.bounds.size.width;
self.bannerView.frame = rect;
}
}

How to obtain the overseas privacy permission setting parameters in TradPlusSDK

#import <TradPlusAds/MsCommon.h>
#import <TradPlusAds/MSConsentManager.h>
MethodDescription
[[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].canCollectPersonalInfoGDPR, 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