Gift Box

app_show_type: 1070

Import Header Files

// if CheetahMobileAds.framework
@import CheetahMobileAds;

// else if CheetahMobileAds.a
#import <CMAPosIDConfig.h>
#import <CMAGiftBoxView.h>

Setup POSID and GiftBoxView

[CMAGiftBoxView sharedInstance].posIDConfig = 
        [[CMAPosIDConfig alloc] initWithOrionPosID:@"YOUR_POSID_FOR_GLOBAL" 
                                liehuPosID:@"YOUR_POSID_FOR_CHINA"];
[CMAGiftBoxView sharedInstance].rootViewController = self;

Set up event notifications

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

// Have a delegate implementation. 
@interface viewController ()<CMAGiftBoxViewDelegate>

[CMAGiftBoxView sharedInstance].delegate = self;

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

#pragma mark - CMAGiftBoxViewDelegate
- (void)giftBoxViewDidLoadAd:(CMAGiftBoxView *)giftBoxView;
{
    NSLog(@"Ad was loaded.");
}

- (void)giftBoxView:(CMAGiftBoxView *)giftBoxView didFailToLoadAdWithError:(CMARequestError *)error;
{
    NSLog(@"didFailToLoadAdWithError %@", error);
}

- (void)giftBoxViewWillPresentScreen:(CMAGiftBoxView *)giftBoxView;
{
    NSLog(@"giftBoxViewWillPresentScreen");
}

- (void)giftBoxViewWillDismissScreen:(CMAGiftBoxView *)giftBoxView;
{
    NSLog(@"giftBoxViewWillDismissScreen");
}

- (void)giftBoxViewWillLeaveApplication:(CMAGiftBoxView *)giftBoxView;
{
    NSLog(@"giftBoxViewWillLeaveApplication");
}

- (BOOL)giftBoxViewDidClicked:(NSURL *)actionURL;
{
    // BOOL If you handled the event, 
    // return YES. 
    // If you want to allow the event to be handled by the next receiver, 
    // return NO
    NSLog("You can handle the URL by yourself. %@", actionURL);
    return YES;
}

Load Ads

[[CMAGiftBoxView sharedInstance] loadAd];

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

- (void)giftBoxViewDidLoadAd:(CMAGiftBoxView *)giftBoxView;

Show Ads

// Check the status of the ad.
if ([CMAGiftBoxView sharedInstance].isReady) {

        // if Ad is ready, then , show the ad.
        self.navigationItem.rightBarButtonItem = 
                [[UIBarButtonItem alloc] 
                    initWithCustomView:[CMAGiftBoxView sharedInstance]];
    }

Last updated