Search code examples
iosswiftiadtabbar

iAd banner in Tab Bar application


I'm working on a tab bar application on which I want to implement an iAd bar in every view/tab.

My current way of doing it is by this line of code:

self.canDisplayBannerAds = true

and adding that to every ViewController

However the problem is that when I go to another tab I get this info in the log about my other view:

2015-07-12 22:19:07.746 TabiAd[17401:1455398] [AppDeveloper] ADBannerView: Unhandled error (no delegate or delegate does not implement didFailToReceiveAdWithError:): Error Domain=ADErrorDomain Code=7 "The operation couldn’t be completed. Ad was unloaded from this banner" UserInfo=0x7f91fc913700 {ADInternalErrorCode=7, NSLocalizedFailureReason=Ad was unloaded from this banner, ADInternalErrorDomain=ADErrorDomain}

Is there any better way to show the ad?


Solution

  • I was making similar application and i handled that this way:

    I created subclass of UITabbarContoller and put all iAd methods and iAd view in there so it will be visible across every tab/view.

    Also i created static boolean variable in my TabBarController class which is true when ad is visible and false when ad isn't visible. I can get it from any view/tab in case i need to adjust content so iAd view won't appear over it. You can get that boolean just by [TabBarController adIsVisible] where TabBarController is name of your subclass of UITabbarController (sorry for Objective-c syntax, i'm unfamiliar with swift but i hope you get it).

    You can also use NSNotificationCenter to handle content size/position adjustment when ad is loaded, so ad doesn't cover anything.