Swift Iad - More Than 10 Instances of Adbannerview Warning and Cgaffinetransforminvert: Singular Matrix Output

Swift iAd - More than 10 instances of ADBannerView warning and CGAffineTransformInvert: singular matrix output

The issue is every time you load your view you are creating a new instance of ADBannerView. What we need to do is create a ADBannerView once in our AppDelegate.swift and then present this ADBannerView on which ever views we would like to have an iAd banner. This is also called a Shared iAd Banner. In this example, I've created an ADBannerView in my AppDelegate.swift and then added it to my ViewController.swift's view.

AppDelegate.swift

import UIKit
import iAd // Import iAd

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, ADBannerViewDelegate { // Include the delegate for our banner

var window: UIWindow?
var adBannerView = ADBannerView() // Create our one ADBannerView

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Set delegate and hide banner initially
adBannerView.delegate = self
adBannerView.hidden = true
return true
}

func bannerViewDidLoadAd(banner: ADBannerView!) {
print("bannerViewDidLoadAd")
adBannerView.hidden = false
}

func bannerViewActionDidFinish(banner: ADBannerView!) {
print("bannerViewActionDidFinish")
}

func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
print("didFailToReceiveAdWithError: \(error)")
adBannerView.hidden = true
}

ViewController.swift

import UIKit

class ViewController: UIViewController {

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate // Create reference to our app delegate

override func viewWillAppear(animated: Bool) {
// Position
appDelegate.adBannerView.center = CGPoint(x: view.frame.midX,
y: view.frame.height - appDelegate.adBannerView.frame.height / 2)
// Add to view
view.addSubview(appDelegate.adBannerView)
}

Don't forget to remove the code from your viewWillDisappear(animated: Bool) function that you added previously. If you click on the banner and then dismiss it this function will be called and removing our banner from our view and setting our banners delegate equal to nil too soon will cause issues.

iOS/Swift: more than 10 instances of ADBannerView

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/…

AdBannerView in TableViewController is shown after TableView

If all you want is a banner ad at the bottom of the screen, you can simply say something like

override func viewDidLoad() {
super.viewDidLoad()
self.canDisplayBannerAds = true
}

And it will work automagically as they say.

I would recommend watching this video to understand the iAd API

More than 10 instances of ADBannerView or ADInterstitialView currently exist : using ARC

Because you clear the ad from the ivar first, you are never removing the ad from the superview. Try rewriting as below:

- (void) viewWillDisappear:(BOOL)animated {
[_UIiAD removeFromSuperview];
_UIiAD.delegate = nil;
_UIiAD = nil;
}


Related Topics



Leave a reply



Submit