Search code examples
iadadbannerview

iAd BannerViewDelegate - warnings are printed on console


Wirh SDK 4.2 and iOS5, it has created some confusion for me. In my new tabbar-based app, I have multiple view controllers. I have carefully checked and re-checked that all iAd delgate methods are present. In fact, I took help of iAdSuite example for this.

I left the app running on the simiulator for a while in a viewController that does not show any test ads. I saw the following message (multiple) logged on the console.

2011-10-30 18:45:07.534 StopAlert[29299:207] ADBannerView: Unhandled error (no delegate or delegate does not implement didFailToReceiveAdWithError:): Error Domain=ADErrorDomain Code=3 "The operation couldn’t be completed. Ad inventory unavailable" UserInfo=0x795d7d0 {ADInternalErrorCode=3, NSLocalizedFailureReason=Ad inventory unavailable}

I am bothered that it points out that "no delegate or delegate does nto implement..." - even though the .m file has these delegate methods. Here they are:

- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
   [self layoutForCurrentOrientation:YES];
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
[self layoutForCurrentOrientation:YES];
}

- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave {
return YES;
}

- (void)bannerViewActionDidFinish:(ADBannerView *)banner {
}

Am I missing something?? I set breakpoints in all 4 of them - and sure enough they are not being hit. The delegate for the banner IS set to "self" and the declaration in the .h file does have ADBannerViewDelegate also.

I am stumped. Can someone help me go past it?

Thanks in advance.


Solution

  • For those who come across this question via search, I now understand what threw me off in the iAdSuite example code (and the tech note on sharing an ad banner across multiple views). The tech note example does the adBanner set up in its applicationDidFinishLaunching. This worked for the iAdSuite because (here's the kicker) it's first view did not attempt to present an adBanner. So the subtle issue ?Sam? and I ran into with an app that wants to show an adBanner on the first view is that the view is already loaded before the app delegate gets the applicationDidFinishLaunching message. In my case I moved my adBanner setup code out of the app delegate and put it into the viewWillAppear of my initial view controller. And at that I only do the initializing setup if adBanner doesn't already exist (which is the case when flow returns to my initial view controller).