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!
// 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]];
}