Banner

app_show_type: 50000/50001/50017

Add a view with class “CMABannerView” in storyboard/XIB.

Import Header Files

// if CheetahMobileAds.framework
@import CheetahMobileAds;

// else if CheetahMobileAds.a
#import <CMABannerView.h>

Setup POSID and BannerView

CMAPosIDConfig *config = [[CMAPosIDConfig alloc] 
        initWithOrionPosID:@"YOUR_POSID_FOR_GLOBAL" 
        liehuPosID:@"YOUR_POSID_FOR_CHINA"];
self.banner.posIDConfig = config;

self.banner.rootViewController = self;

// if you want to show banner "Small"
self.banner.adType = kCMABannerAdTypeBanner;
// else if you want to show banner "Medium"
self.banner.adType = kCMABannerAdTypeMediumRectangle;

Set up event notifications

To set up event notification, insert the line before your load request call:

// Have a delegate implementation. 
@interface ViewController ()<CMABannerViewDelegate>

self.banner.delegate = self;

The following sample illustrates how to log each of the events available in CMABannerViewDelegate:

#pragma mark - CMABannerViewDelegate

- (void)bannerViewDidLoadAd:(CMABannerView *)banner;
{
    NSLog(@"Ad was loaded.");
}

- (void)bannerView:(CMABannerView *)banner didFailToLoadAdWithError:(CMARequestError *)error;
{
    NSLog(@"didFailToLoadAdWithError %@", error);
}

- (void)bannerViewWillPresentScreen:(CMABannerView *)banner;
{
    NSLog(@"bannerViewWillPresentScreen");    
}

- (void)bannerViewWillDismissScreen:(CMABannerView *)banner;
{
    NSLog(@"bannerViewWillDismissScreen");    
}

- (void)bannerViewWillLeaveApplication:(CMABannerView *)banner;
{
    NSLog(@"bannerViewWillLeaveApplication");    
}

Load Ads

[self.banner loadAd];

Show Ads

If the ad is loaded successfully, following function will be called!

- (void)bannerViewDidLoadAd:(CMABannerView *)banner;

Then, ad will be showed on the CMABannerView.

Last updated