AdWhirl on the iPad

UPDATE 01/30/11 After I wrote this article and continued experimenting with AdWhirl, I became sorely disappointed with the fact that AdWhirl does not support MobClix. MobClix does however support AdMob (the creators of AdWhirl). MobClix provides an ad mediation platform which I now believe to be more robust than AdWhirl.  I’ve abandoned AdWhirl in favor of MobClix. Unfortunately, at this time, MobClix does not support iAds on the iPad out of the box. There are ways around this caveat using Open Allocations which I may write about in a future post.
So your ad requests are going up, GREAT! But for some reason or another, your advertising revenue is going down. Advertising budgets are low, so low, that major advertising agencies, including Apple’s iAds, are having a hard time filling it’s publisher’s demands. As developers, we need to squeeze as much as we can out of our hard work, so we need to fill those empty ad slots! That’s where ad mediation comes in.

To see the code and skip the commentary, scroll down to the end of the post.

AdMob’s AdWhirl solves the problem by providing an open-source mobile ad mediation solution that will fill your ad requests in an order and configuration that you choose. Just sign up for each advertising agency individually (AdMob, iAds, Google AdSense, MobClix, etc) and AdWhirl will serve those ads in the priority and ratio of your choosing.

In it’s current state, 2.6.2, AdWhirl supports iPhone (and iPod Touch) devices but not iPad. I was disappointed when I launched my universal binary (Checkin Map) on my iPad, after the iPhone version had worked flawlessly, only to see my ad as a tiny rectangle in a sea of empty UIView which should have been filled entirely by my ad.

I did some quick research and found that AdWhirl does not know when or how they will be integrating iPad support into their SDK. They seemed indecisive about it because of the technical challenges and considerations involved.

So here’s a simple solution that worked for me. The idea is simple:

  1. Check if the device is an iPad or iPhone
  2. Request the appropriate size ad from the ad network in the ad network’s adapter
  3. Set any other variables, keys, IDs, etc, based on your device
  4. Once the ad is received, resize your ad’s UIView to fit the ad

Here’s an example for AdMob:

In AdWhirlAdapterAdMob.m:

- (void)getAd {

	// Request the right size ad for your device
	CGSize adSize = ADMOB_SIZE_320x48;
	if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
		adSize = ADMOB_SIZE_748x110;

	AdMobView *adMobView = [AdMobView requestAdOfSize:adSize withDelegate:self];
	self.adNetworkView = adMobView; 

}

In your view controller that implements the AdWhirlDelegate protocol, set your publisher ID based on your device

- (NSString *)admobPublisherID {

	if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
		return @"your_iPad_publisher_id";
	} else {
		return @"your_iPhone_publisher_id";
	}
}

And resize your ad view for the new ad:

- (void)adWhirlDidReceiveAd:(AdWhirlView *)adWhirlView {

	[UIView beginAnimations:@"AdWhirlDelegate.adWhirlDidReceiveAd:" context:nil];

	[UIView setAnimationDuration:0.7];

	CGSize adSize = [self.adWhirlView actualAdSize];

	CGRect newFrame = self.adWhirlView.frame;

	newFrame.size = adSize;

	newFrame.origin.x = (self.view.bounds.size.width - adSize.width)/ 2;

	self.adWhirlView.frame = newFrame;

	[UIView commitAnimations];

}