Saturday, June 26, 2010

Ad Viewer: supporting more interaction

Next I need want to implement the delegate actions for the ads.  These are the interaction the iAD network has with my class.

Add protocol to my view controller




#import

@interface adViewerViewController : UIViewController {

}

This way I will have the definition as an ADBanner delegate.  I first implemented a very simple set of callbacks to verify that I set my delegate in interface builder correctly.

//The Add banner delgate methods.
// This method is invoked each time a banner loads a new advertisement. Once a banner has loaded an ad, 
// it will display that ad until another ad is available. The delegate might implement this method if 
// it wished to defer placing the banner in a view hierarchy until the banner has content to display.
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
self.view.backgroundColor=[UIColor redColor];
}

// This method will be invoked when an error has occurred attempting to get advertisement content. 
// Possible error codes defined as constants in ADManager.h.
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
// Update the text display with informaito about the error.
}

// This message will be sent when the user taps on the banner and some action is to be taken.
// Actions either display full screen content in a modal session or take the user to a different
// application. The delegate may return NO to block the action from taking place, but this
// should be avoided if possible because most advertisements pay significantly more when 
// the action takes place and, over the longer term, repeatedly blocking actions will 
// decrease the ad inventory available to the application. Applications may wish to pause video, 
// audio, or other animated content while the advertisement's action executes.
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
self.view.backgroundColor=[UIColor cyanColor];
// All we do is display ads, we have NO desire to block it.
return true;
}

// This message is sent when a modal action has completed and control is returned to the application. 
// Games, media playback, and other activities that were paused in response to the beginning
// of the action should resume at this point.
- (void)bannerViewActionDidFinish:(ADBannerView *)banner
{
}

No comments:

Post a Comment