AdWhirl on the iPad
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:
- Check if the device is an iPad or iPhone
- Request the appropriate size ad from the ad network in the ad network’s adapter
- Set any other variables, keys, IDs, etc, based on your device
- 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];
}





Programming and design are both my play and my work. I feel like a digital alchemist on most days and look forward to the creative process. I love discovering new ways to apply the magic of technology to complex communication challenges. Most of all, the worlds of technology and design feed my soul!