Skip to content

Adding iAd to Your Projects

I noticed that there is no official sample code for including iAd banners in your projects. Knowing Apple “version zero” demoware, I thought it might be a good idea to build a small project to evaluate iAd.

It works out well; there is effectively only one class that you have to think about, ADBannerView – although you will see log messages from at least one other class messing up your log files; and one delegate protocol to implement, with optional methods.

In practice, there are a few scenarios that you will have to handle. The highest priority for most people will be handling situations where there is no connection to the ad server, so that you should avoid displaying an ad. There’s a delegate method for that, both one for notifying the delivery of an ad, and a fail method.

Then you may way to switch orientations; all ads should be supplied in both formats, but a quirk of the system means that ads align to their bottom, and as landscape ads are shorter than portrait ads, a top aligned ad will have to be shifted up to cope with this.

See the code for examples. I copied liberally from the Apple documentation, with just some minor tweaks to implement basic solutions for these problems. My code won’t work correctly for bottom aligned ads, but it will be trivial to adjust, as it is the simpler case. I position the banner off-screen to start with, then move it on-screen to a designated location when the ad is delivered.

Source for the project here.

{ 1 } Comments

  1. Robert | February 17, 2011 at 2:59 am | Permalink

    Hi Paul. Thanks for the great info and samples you post on your blog.

{ 1 } Trackback

  1. iAd Demos » iAd Sample Project | July 10, 2010 at 3:26 am | Permalink

    […] dev, if you need a sample project to see how iAd is implemented, check out this blog post from Paul Lynch here Uncategorized […]

Post a Comment

Your email is never published nor shared. Required fields are marked *