Bob
Bob

Reputation: 993

iAd banner not loading when tapped

I have an iAd banner located at the bottom of my app. The banner displays fine on test devices and the delegate methods appear to be called appropriately.

My issue is. When I tap the "You're Connected To iAd" banner, nothing is loaded. Normally, I would expect to see a another full screen iAd view pop up. I see the banner darken when I tap it and then it returns to normal when I remove my finger.

bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) does fire and willLeave is == false.

class ViewController: UIViewController, UIGestureRecognizerDelegate, ADBannerViewDelegate, GADBannerViewDelegate {
var bannerView: ADBannerView!

override func viewDidLoad() {
    super.viewDidLoad()
    self.bannerView = ADBannerView()
    self.bannerView.frame =  CGRectMake(0, view.frame.height-50, view.frame.width, 50)
    self.bannerView.delegate = self
    self.view.addSubview(bannerView)
    }
}

Upvotes: 1

Views: 107

Answers (2)

Chetan Prajapati
Chetan Prajapati

Reputation: 2297

add this - ADBannerViewDelegate

create variable - var adBanner = ADBannerView()

In viewDidLoad()

        adBanner = iADManager.sharedInstance
        adBanner.delegate = self
        if DeviceType.IS_IPAD {
            adBanner.frame = CGRectMake(0, 20, self.view.frame.width, 65);
        }
        else {
            adBanner.frame = CGRectMake(0, 20, self.view.frame.width, 50);
        }

Delegate Methods [if fetched successfully ad then this will add subviews otherwise remove from view]

func bannerViewDidLoadAd(banner: ADBannerView!) {
        self.view.addSubview(banner)
    }

    func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
        banner.removeFromSuperview()
    }

func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
    return true
}

Below is My shareInstance class. This will more helpful for memory management and loading ads.

class iADManager{

    class var sharedInstance: ADBannerView {
        struct Static {
            static var onceToken: dispatch_once_t = 0
            static var instance: ADBannerView? = nil
        }
        dispatch_once(&Static.onceToken) {
            Static.instance = ADBannerView(adType: ADAdType.Banner)
        }
        return Static.instance!
    }
}

Upvotes: 2

Bob
Bob

Reputation: 993

The issue was that I implemented...

func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {NSLog("Banner Leaving... \(willLeave)")
    return willLeave
}

willLeave was set to false so I either had to return true or not implement the method. I chose to just return true

Upvotes: 1

Related Questions