loadADWithPlacementID:
method once. Subsequent displays and refreshes will be automatically executed by the SDK.BannerVC.m
in DemoVersion V6.4.39 and above (including V6.4.39) supports passing in a controller object when loading ads to adapt to the requirement of some ad platforms that the loading controller and display controller must match. If you cannot adapt to passing in a controller object for some reasons, it may cause the problem of invalid clicks after these ad platforms are displayed. If you need to adapt, please use the following APIs together and pass in the same controller object:
objc Copy/// Load banner ad /// @param placementID Ad placement ID /// @param extra Extra parameters /// @param viewController Target controller, for example, the popup window after Banner click will use this controller, you need to reference it, SDK internally uses weak reference /// @param delegate Delegate object - (void)loadADWithPlacementID:(NSString *)placementID extra:(NSDictionary *)extra viewController:(UIViewController *)viewController delegate:(id<ATAdLoadingDelegate>)delegate; /// Check if banner ad is ready /// @param placementID Ad placement ID /// @param showViewController Pass in the same object as the controller in the loading method -[ATAdManager loadADWithPlacementID:extra:viewController:delegate:] - (BOOL)bannerAdReadyForPlacementID:(NSString *)placementID showViewController:(UIViewController *)showViewController; /// Get BannerView object for display /// @param placementID Ad placement ID /// @param ATShowConfig config Configuration object, if viewController was passed in loadADWithPlacementID, then the same object needs to be passed here /// @param nativeMixBannerViewBlock For custom banner ads, returns components for custom layout - (nullable ATBannerView *)retrieveBannerViewForPlacementID:(NSString *)placementID config:(ATShowConfig *)config nativeMixBannerViewBlock:(nullable NativeMixBannerViewBlock)nativeMixBannerViewBlock;
Banner ads on different platforms have certain rule restrictions:
- Proportional scaling rule: For example, if the banner ad size configured in the backend is 640*100, to fill the screen width, calculate height H = (screen width * 100)/640; then the filled size is: CGSizeMake(screen width, H);
- Fixed size rule: Select a fixed size in the backend configuration, and also set the same fixed size in the code
- Adaptive rule: Only supported by some ad platforms, and you need to select a non-fixed size style in the backend. For code details, see the method example in Demo -
[AdLoadConfigTool banner_loadExtraConfigAppendAdmob:loadConfigDict]
- The extra dictionary in this step supports passing in relevant parameters for configuring ads and your custom parameters. You can view more information about extra parameters here.
//Import header file
#import <AnyThinkBanner/AnyThinkBanner.h>
@interface BannerVC () <ATBannerDelegate>
@property (nonatomic, strong) ATBannerView *bannerView;
@property (nonatomic, assign) BOOL hasLoaded; // Ad loading status identifier
@end
@implementation BannerVC
//Ad placement ID
#define BannerPlacementID @"b680a1e7874fce"
//Scene ID, optional, can be generated in the backend. If not available, pass an empty string
#define BannerSceneID @""
//Please note that banner size needs to be consistent with the ratio configured in the backend
#define BannerSize CGSizeMake(320, 50)
#pragma mark - Load Ad
/// Load ad
- (void)loadAd {
[self showLog:kLocalizeStr(@"Clicked load ad")];
NSMutableDictionary * loadConfigDict = [NSMutableDictionary dictionary];
/*
Note that banner ads on different platforms have certain restrictions. For example, the configured banner ad is 640*100. In order to fill the screen width, the height H = (screen width *100)/640 is calculated. Then the extra size of the load is (screen width: H).
Note that banner ads on different platforms have certain restrictions. For example, the configured banner AD is 640*100. In order to fill the screen width, the height H = (screen width *100)/640 is calculated. Then the extra size of the load is (screen width: H).
*/
[loadConfigDict setValue:[NSValue valueWithCGSize:BannerSize] forKey:kATAdLoadingExtraBannerAdSizeKey];
//Set custom parameters
[loadConfigDict setValue:@"media_val_BannerVC" forKey:kATAdLoadingExtraMediaExtraKey];
//Start loading
[[ATAdManager sharedManager] loadADWithPlacementID:BannerPlacementID extra:loadConfigDict delegate:self];
}
#pragma mark - Ad placement delegate callbacks
/// Ad placement loading completed
/// - Parameter placementID: Ad placement ID
- (void)didFinishLoadingADWithPlacementID:(NSString *)placementID {
self.hasLoaded = YES;
}
/// Ad placement loading failed
/// - Parameters:
/// - placementID: Ad placement ID
/// - error: Error information
- (void)didFailToLoadADWithPlacementID:(NSString *)placementID error:(NSError *)error {
self.hasLoaded = NO;
}
Statistics scene arrival rate, displayed in the backend's Data Reports -> Funnel Analysis Report -> Arrival at Ad Scene, called before showing ads.
#pragma mark - Show Ad
/// Show ad
- (void)showAd {
//Scene statistics function, displayed in the backend's Data Reports -> Funnel Analysis Report -> Arrival at Ad Scene, called before showing ads. Optional integration
[[ATAdManager sharedManager] entryBannerScenarioWithPlacementID:BannerPlacementID scene:BannerSceneID];
//Check if ready
if (![[ATAdManager sharedManager] bannerAdReadyForPlacementID:BannerPlacementID]) {
[self loadAd];
return;
}
//Show configuration, Scene passes in the backend scene ID, if not available pass an empty string, showCustomExt parameter can pass in custom parameter string
ATShowConfig *config = [[ATShowConfig alloc] initWithScene:BannerSceneID showCustomExt:@"testShowCustomExt"];
//Show ad
ATBannerView *bannerView = [[ATAdManager sharedManager] retrieveBannerViewForPlacementID:BannerPlacementID config:config];
if (bannerView != nil) {
//Assignment
bannerView.delegate = self;
bannerView.presentingViewController = self;
bannerView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:bannerView];
self.bannerView = bannerView;
//Layout
[self.bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.view);
make.height.equalTo(@(BannerSize.height));
make.width.equalTo(@(BannerSize.width));
make.top.equalTo(self.textView.mas_bottom).offset(5);
}];
}
}
/// Get display revenue
/// - Parameters:
/// - placementID: Ad placement ID
/// - extra: Extra information dictionary
- (void)didRevenueForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra {
}
/// Close button clicked (when user clicks the close button on the banner)
/// - Parameters:
/// - bannerView: Banner ad view object
/// - placementID: Ad placement ID
/// - extra: Extra information dictionary
- (void)bannerView:(ATBannerView *)bannerView didTapCloseButtonWithPlacementID:(NSString *)placementID extra:(NSDictionary *)extra {
// Received close button click callback, remove bannerView
[self removeAd];
}
/// Banner ad has been shown
/// - Parameters:
/// - bannerView: Banner ad view object
/// - placementID: Ad placement ID
/// - extra: Extra information dictionary
- (void)bannerView:(ATBannerView *)bannerView didShowAdWithPlacementID:(NSString *)placementID extra:(NSDictionary *)extra {
}
/// Banner ad was clicked
/// - Parameters:
/// - bannerView: Banner ad view object
/// - placementID: Ad placement ID
/// - extra: Extra information dictionary
- (void)bannerView:(ATBannerView *)bannerView didClickWithPlacementID:(NSString *)placementID extra:(NSDictionary *)extra{
}
/// Banner ad has auto refreshed
/// - Parameters:
/// - bannerView: Banner ad view object
/// - placementID: Ad placement ID
/// - extra: Extra information dictionary
- (void)bannerView:(ATBannerView *)bannerView didAutoRefreshWithPlacement:(NSString *)placementID extra:(NSDictionary *)extra {
}
/// Banner ad auto refresh failed
/// - Parameters:
/// - bannerView: Banner ad view object
/// - placementID: Ad placement ID
/// - error: Error information
- (void)bannerView:(ATBannerView *)bannerView failedToAutoRefreshWithPlacementID:(NSString *)placementID error:(NSError *)error {
}
/// Banner ad has opened or jumped to deep link page
/// - Parameters:
/// - bannerView: Banner ad view object
/// - placementID: Ad placement ID
/// - extra: Extra information
/// - success: Whether successful
- (void)bannerView:(ATBannerView *)bannerView didDeepLinkOrJumpForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra result:(BOOL)success {
}
#pragma mark - Destroy Ad
- (void)removeAd {
[self.bannerView destroyBanner];
[self.bannerView removeFromSuperview];
self.bannerView = nil;
self.hasLoaded = NO;
}