AdWhirl : adapt the banner size for iPad

Even if AdMob is now proposing mediation and thus the possibility to use House Adds, I found their management not really simple : on my understanding (let me know if I’m false), to display House Ads, you have to create a campaign with a beginning and a end date, then you have to define the number of display you want….. This is not the way I see House Ads. For me House Ads are here to allow auto-promotion or rating of our apps. Thus I want the campaign to run all over the time and the House Ads to be displayed 10% of the time….

Thus, the aim of this post : AdWhirl manage House Ads the way I want BUT it doesn’t support adapted banner size for iPad. I found in this post the way to modify the banner size for iPad and have them well displayed with AdMob.

This is really simple : modify the AdMob adapter from AdWhirl and add some method in the AdWhilrDelegate Methods.

1 – In the AdMob adapter in AdWhirl SDK,  AdWhirlAdapterGoogleAdMobAds.m, modify the getAd() method:

At the start of the method add these lines:

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

  CGRect adFrame = CGRectMake(0, 0, adSize.width, adSize.height);

Locate the line

 GADBannerView *view =
    [[GADBannerView alloc] initWithFrame:kAdWhirlViewDefaultFrame];

Replace with:

  GADBannerView *view =
    [[GADBannerView alloc] initWithFrame:adFrame];

2 – In your view controller, add the following methods to the AdWhirl Delegate Methods :

- (void)adWhirlDidReceiveAd:(AdWhirlView *)adWhirlView {
     [self adjustAdSize];

And define the adjustAdSize method :

- (void)adjustAdSize {
    [UIView beginAnimations:@"AdResize" context:nil];
    [UIView setAnimationDuration:0.7];
    CGSize adSize = [adView actualAdSize];
    CGRect newFrame = adView.frame;
    newFrame.size.height = adSize.height;
    newFrame.size.width = adSize.width;
    newFrame.origin.x = (self.view.bounds.size.width - adSize.width)/2;
    adView.frame = newFrame;
    [UIView commitAnimations];

That’s it ! Really easy !

This entry was posted in app development, iOS, tutoriels. Bookmark the permalink.