RBAdView a simple drop in iAD implementation

It’s pretty easy to add iAds to your iPhone app. The simplest thing you can do is drop an AdBannerView onto your interface in Interface Builder. That is the bare minimum you need to get them working. The problem with that is that ads don’t always load. When they don’t load, they leave an empty space and that looks kinda shitty. So what do you do?
You implement the iAd delegate methods and handle the errors. I hated doing that every time I added a new ad so I built RBAdView.

RBAdView is a UIButton subclass that shows an iAd when it can. When the iAd fails to load, it behaves just like a regular UIButton.

To use it, you can just put it in interface builder and be done, or you can add it programatically.

   RBAdView *rbBanner = [[RBAdView alloc] initWithFrame:CGRectMake(0, 100, 320, 50)];
   [rbBanner setBackgroundImage:[UIImage imageNamed:@"RBAd0"] forState:UIControlStateNormal];

   rbBanner.actionBlock = ^(ADBannerView* banner, BOOL willLeaveApp){
      NSLog(@"Banner will open %@",banner);
      return YES;
   };

   rbBanner.finishedBlock = ^(ADBannerView* banner){
      NSLog(@"Banner finished %@",banner);
   };

   [self.view addSubview:rbBanner];

There is an actionBlock that you can add that will get called when an iAd gets pressed. It will let you do things like pause your game before the ad takes over the screen.

The finishedBlock gets called when the user closes the ad.

If you have any trouble getting it to build, make sure you add the iAd framework to your project.

Check it out on GitHub.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>