Search code examples
iosios5iadadwhirl

ads in universal app + ad persisting even when viewController changes


I'm implementing ads for the first time in an app that will be universal. I've followed a few tutorials and sorta|kinda have it working - using adWhirl, iAd, adMob. The tutorials were a bit simplistic though and I'm wondering if there are any open source universal ad template/library projects out there.

I've seen this and while helpful, the tutorial code is kind of broken/limited.

The specific questions I have (iOS5+ universal app):

  • In an app with a navController where the UIViewController can segue multiple times to other controllers and then back again, do I need to set up the ad stuff in each viewController or is there some way I can have the ad layer/view persist across multiple VC views?

  • Ad sizes - In my test app, running on iPad I am getting ads but the size is for iPhone. In adWhirl it didn't seem possible to specify universal - only iPhone or Android. I've seen other iPad apps that seem to have a problem presenting ads because of the size - ads appear in weird places, etc. Is there some universal solution to the issue of ad sizes in universal apps?


Solution

  • For your first question, I would recommend that you use a singleton approach for your adView. You can find a similar singleton approach for an AdMob adView here. Tweaking that with your AdWhirl view instead shouldn't be bad at all. For each view that is displayed then, you could just do something like:

    - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
        shared = [AdWhirlMasterViewController singleton];
        [shared resetAdView:self];
    }
    

    For your second question, I wonder if you can't just make some minor modifications to your adapter code to get iPad ads to show. So, for example, for AdMob adapter's getAd: method, you'd probably have something that looks like:

     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 
            adSize = kGADAdSizeLeaderboard; 
     } else { 
            adSize = kGADAdSizeBanner; 
     } 
    

    Then create your GADBannerView doing something similar to:

    GADBannerView *view =
          [[GADBannerView alloc] initWithAdSize:adSize];