Note that there are some explanatory texts on larger screens.

plurals
  1. POAvoiding recursive bannerView: didFailToReceiveAdWithError: on iPad
    text
    copied!<p>I have an iPhone app that uses an iAd, with a fallback to an AdMob ad:</p> <pre><code>- (void)bannerViewDidLoadAd:(ADBannerView *)banner { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.3f]; adBannerView.frame = CGRectMake(0, 410, 320, 50); [UIView commitAnimations]; // hide the admob ad if(adMobView != nil &amp;&amp; adMobView.superview != nil) { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.3f]; adMobView.frame = CGRectMake(0, 460, 320, 48); [UIView commitAnimations]; } } - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.3f]; // hide banner adBannerView.frame = CGRectMake(0, 460, 320, 50); [UIView commitAnimations]; if(adMobView != nil &amp;&amp; adMobView.superview != nil) { [adMobView requestFreshAd]; } else { adMobView = [AdMobView requestAdWithDelegate:self]; adMobView.frame = CGRectMake(0, 460, 320, 48); [self.view addSubview:adMobView]; } } </code></pre> <p>This works perfectly well on an iPhone. However, when the app is run on an iPad, this recurses; the <code>[self.view addSubview:adMobView];</code> (specifically the call to 'self.view') calls loadView as per <a href="http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006926-CH3-SW2" rel="nofollow">the ViewController.view reference</a>, which tries to layout the AdBannerView again, which triggers the failure again.</p> <p>I figure it has something to do with the bounds of the window on iPad being larger / different than on iPhone, and the rules that determine whether to attempt to load an AdBanner or not.</p> <p>One solution is probably to adjust the bounds I've hardcoded to be further outside (and thus outside the iPad's larger range). Another solution is to avoid the self.view call / risk of recursion entirely and do it another way - however, the AdMobView is a bit persnickety and really wants to be instantiated by <code>requestAdWithDelegate</code>, which would be premature if I put it in viewDidLoad.</p> <p>Which approach is the wise one?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload