15

I am getting this warning after 10 screenviews.

More than 10 instances of ADBannerView or ADInterstitialView currently exist. This is a misuse of the iAd API, and ad performance will suffer as a result. This message is printed only once.

I have implemented AdBannerView through InterfaceBuilder. I am not explicitely creating an ADBannerView programmatically each time the view is loaded.

I am just referencing the AdBannerView as an @IBOutlet:

@IBOutlet weak var iAdsBanner: ADBannerView!

and hiding/showing it by changing its position, as suggested by Apple documentation.

Why am I getting this kind of error?

Daniele B
  • 19,801
  • 29
  • 115
  • 173

1 Answers1

12

Why are your making an outlet for bannerView. After iOS 7 things have been changed. If you want iAds then all you need to do is add the iAdsFramework, import the framework in your UIViewController and in your viewDidLoad() write the following code

 self.canDisplayBannerAds = true;

It will start displaying ads.

UPDATE Forget the canDisplayBannerAds thing as your requirement is different. Just create a single instance for banner View in your AppDelegate and in your view controller get that instance , set frames and add it as subview and don't forget to remove it when your controller disappears.check this link you will get the idea. stackoverflow.com/questions/28514758/…

Community
  • 1
  • 1
Muneeba
  • 1,756
  • 10
  • 11
  • it's because i need to place the banner in a certain position, following specific constraints – Daniele B Dec 16 '15 at 05:46
  • Alright, then you should properly remove your bannerView in your controller's viewDidDisappear if you are creating instance for every screen. Or make only one instance of adBannerView like in AppDelegate and add/remove it on your controller's view – Muneeba Dec 16 '15 at 05:52
  • I have a banner in 2 different view controllers. I believe I am not creating an instance everytime, as I just added the banners using InterfaceBuilder, referencing them in the code as an outlet. If I create just one instance in the AppDelegate, how would I be able to position them in the Interface Builder? – Daniele B Dec 16 '15 at 05:56
  • but they are active and displaying ads though your controller is not visible. you will need to add them programmatically. like subview and you need to define frames for your banner view or you can also add it as subview on window. – Muneeba Dec 16 '15 at 05:59
  • I am confused now. If I understand correctly, you are saying I should not add them using InterfaceBuilder. But how should I create them, using `self.canDisplayBannerAds = true` or creating the instance in the AppDelegate? In case I create the instance in the AppDelegate, should I create two different istances (1 for each view controller) or just one? and should I still hide them using `viewDidDisappear`? – Daniele B Dec 16 '15 at 06:03
  • don't be confused :). Forget the canDisplayBannerAds thing as your requirement is different. Just create a single instance for banner View in your AppDelegate and in your view controller get that instance , set frames and add it as subview and don't forget to remove it when your controller disappears.check this link you will get the idea. http://stackoverflow.com/questions/28514758/swift-iad-more-than-10-instances-of-adbannerview-warning-and-cgaffinetransform – Muneeba Dec 16 '15 at 06:06
  • Ok thanks! Can you confirm if it's enough to create just 1 instance, or should I create two different instances, one for each of the two view controllers – Daniele B Dec 16 '15 at 06:12
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/98060/discussion-between-muneeba-and-daniele-b). – Muneeba Dec 16 '15 at 06:13