Search code examples
admobinterstitial

How do I show multiple Admob interstitials?


I have two portions of code

Preload

interestial = [[GADInterstitial alloc] init];
[interestial loadRequest:request]

Show

[interestial presentFromRootViewController:]

What should I do to show interstitial next time properly ? With ARC and without

Preload

if(arc) [interstitial release];
interstitial = [[GADInterstitial alloc] init];
[interstitial loadRequest:request]

Show

[interstitial presentFromRootViewController:self]

-- or

Init

interstitial = [[GADInterstitial alloc] init];

Preload

[interstitial loadRequest:request]

Show

[interstitial presentFromRootViewController:self]

-- or

Init

interstitial = [[GADInterstitial alloc] init];
[interstitial loadRequest:request];

Preload

// nothing

Show

[interstitial presentFromRootViewController:self];
[interstitial loadRequest:request];

If last option is not correct then how much time should I wait for preloading after present is called? or should I listen for delegate or wait for some user action to start preloading?


Solution

  • You should listen for the interstitialDidDismissScreen: method from GADInterstitialDelegate. That'll tell you when you're finished with the first interstitial, and you can start preparing for the next one.

    So you'll have something like:

    // During init time.
    self.interstitial = [[GADInterstitial alloc] init];
    self.interstitial.adUnitID = MY_INTERSTITIAL_UNIT_ID;
    self.interstitial.delegate = self;
    [self.interstitial loadRequest:[GADRequest request]];
    
    ...
    
    
    // During show time.
    [self.interstitial presentFromRootViewController:self];
    
    ...
    
    // When user dismisses the interstitial.
    - (void)interstitialWillDismissScreen:(GADInterstitial *)interstitial {
      self.interstitial.delegate = nil;
      if (!arc) {
        [self.interstitial release];
      }
    
      // Prepare next interstitial.
      self.interstitial = [[GADInterstitial alloc] init];
      self.interstitial.adUnitID = MY_INTERSTITIAL_UNIT_ID;
      self.interstitial.delegate = self;
      [self.interstitial loadRequest:[GADRequest request]];
    }