Banner
1. Methods that need to be rewritten
- Developers need to inherit TradPlusBaseAdapter and rewrite related methods:
- When developers call the
loadAdWithSceneId:
API ofTradPlusAdBanner
, theloadAdWithWaterfallItem:
method of the custom Adapter will be called. - When developers call the
isAdReady
API ofTradPlusAdBanner
, theisReady
method of the custom Adapter will be called - When developers call the
showWithSceneId:
API ofTradPlusAdBanner
, theisReady
andgetCustomObject
methods of the custom Adapter will be called in sequence. - In the default automatic display mode of
TradPlusAdBanner
, the SDK will automatically callshowWithSceneId
after loading is completed.
- When developers call the
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 |
- (id)getCustomObject | Returns the banner ad instance displayed when show Ad | id | Used to return the banner ad instance after loading is completed |
- (BOOL)isReady | ----- | Bool | Bool |
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
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
orAdLoadFailWithError
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];
}
- Return the banner ad instance for display in the
getCustomObject
method
//example
- (id)getCustomObject
{
return self.bannerView;
}
- Implement the display of the custom platform in the
showAdFromRootViewController:
method
//example
- (BOOL)isReady
{
return (self.bannerView != nil);
}
- 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
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>
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 |