Creating and Displaying Ads

Overview

This is the second part of a series of three articles that demonstrate integrating Burstly ads in to your application. Please refer here http://support.burstly.com/kb/ios/incorporating-the-sdk for the first part.


Burstly SDK provides a means to monetize your application by placing rich media ads from varied ad networks anywhere in your application. Creating a banner ad placement entails setting up an OAIAdManager instance and adding its view property to a UIViewController�s view hierarchy


All it takes is 5 simple steps to get your ads rolling on screen!

  • Import "OAIAdManager.h" and OAIAdManagerDelegateProtocol.h"
  • Declare an instance of OAIAdManager in your View Controller
  • Add the ad view to you view hierarchy
  • Implement the three required delegate callback methods
  • Request an ad
Step 1- Import

Import the OAIAdManager.h and OAIAdManagerDelegateProtocol.h files in your viewController.h and confirm to the OAIAdManagerDelegate protocol.

#import "OAIAdManager.h"
#import "OAIAdManagerDelegateProtocol.h"


@interface beginnerViewController : UIViewController \OAIAdManagerDelegate\ {
    OAIAdManager *adManager;
}

              
Step 2- Declare

Allocate and initialize an instance of OAIAdManager in your viewController.m. Add OAIAdManager's view to a visible view.

- (void)viewDidLoad {
        [super viewDidLoad];

        adManager = [[OAIAdManager alloc] initWithDelegate:self];
        [self.view addSubview:adManager.view];
}

              
Step 3- Implement

Implement the following required OAIAdManager delegate callbacks in your viewController.m.

- (NSString *)publisherId {
    return @"Replace with publisherId provided by your account manager";
}

- (NSString*)getZone {
    return @"Replace with zoneId provided by your account manager";
}

- (UIViewController*)viewControllerForModalPresentation {
    return self;
}

              
Step 4- Request an Ad

To display an ad you must call requestRefreshAd on your OAIAdManager instance. You may want the banner ads to refresh at specific intervals. Implement the optional delegate method defaultSessionLife to periodically refresh ads. We recommend setting a value above 20 seconds.

 [adManager requestRefreshAd];
              
- (CGFloat)defaultSessionLife {
    return 20.0f;
}
              
Step 5- Position the ad view

The OAIAdManager's view is dynamically re-sized depending on the creatives served. To you better manage the positioning of the ad views, we have introduced the concept of Anchor and Anchor points.

An anchor sets the baseline from which the ad view will be resized. For example, setting a top anchor will resize the view downwards, while setting a bottom anchor will resize the view upwards. So, for instance, if you place your ad view at the bottom of your view, you would want the view to resize upwards from the bottom and thus would set a bottom anchor. The OAIAdManager view�s anchor is controlled by the anchor delegate method:

- (Anchor)burstlyAnchor {
        return Anchor_Bottom;
}
              

Setting the anchor does not position the adView based on its super view. To do that you have to implement the anchorPoint delegate method, that instructs the adManager to position the adView at a specific point in the superView. For example, an anchor point of (160, 0) with a top anchor will resize the view so it expands down and out from (160, 0) mark of the super view. Likewise, an anchor point of (160, 480) with a bottom anchor will resize the view so it expands up and out from (160, 480).

- (CGPoint)burstlyAnchorPoint {
        return CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height);
}
              

At this point you should be able to see a banner ad on the bottom of your screen.

Screen_shot_2011-08-10_at_6.25.35_PM.png

Displaying Interstitials and Videos

In addition to banner ads, the Burstly SDK enables you to display interstitial creatives as well as videos in high definition.

Implement the following delegate to pause any activity that visually changes the state of your app. eg: A running timer in your game

- (void)adManager:(OAIAdManager*)manager adNetworkControllerPresentFullScreen:(NSString*)aNetwork;
              

Implement the following delegate to unpause and resume any paused activity.

- (void)adManager:(OAIAdManager*)manager adNetworkControllerDismissFullScreen:(NSString*)aNetwork;
              
Pre-Caching Interstitials

In many cases, it is desirable to precache interstitials to have an ad ready to display without lag time. Fortunately, the Burstly SDK has a built in precaching mechanism for interstitials.


Instead of calling

(void)requestRefreshAd;

you should call the following instance method to precache ads

(void)precacheAd; 

In response, the OAIAdManager with either call the following if the ad was successfully cached

(void)adManager:(OAIAdManager*)manager didPrecacheAd:(NSString*)aNetwork;

or, if the precaching attempt failed, you will receive the following callback notification

(void)adManager:(OAIAdManager*)manager failedToLoad:(NSString*)aNetwork;

Finally, when you ready to display the precached ad, you should call

(void)requestRefreshAd;