Sasha Shumylo
Sasha Shumylo

Reputation: 137

bannerViewDidLoadAd is not called

iAD delegate never calls, although I set it in viewWillAppear.

in AppDelegate

var UIiAd: ADBannerView = ADBannerView()

in ViewController

var UIiAd: ADBannerView = ADBannerView()

 func appdelegate() -> AppDelegate {
    return UIApplication.sharedApplication().delegate as! AppDelegate
}

override func viewWillAppear(animated: Bool) {
    var SH = UIScreen.mainScreen().bounds.height

    UIiAd.delegate = self
    UIiAd = self.appdelegate().UIiAd
    UIiAd.frame = CGRectMake(0, SH - 50, 0, 0)
    self.view.addSubview(UIiAd)
}

func bannerViewDidLoadAd(banner: ADBannerView!) {
    UIView.beginAnimations(nil, context: nil)
    UIView.setAnimationDuration(10)
    UIiAd.alpha = 0.5
    println("hello")
    UIView.commitAnimations()
}

The funny think that adBanner actually show test advertising.

UDP: I did understand what was wrong. To display iAd, all you need is to set self.canDisplayBannerAds = true, thats it. But you don't have any access to delegates of banned that was created.

Upvotes: 1

Views: 254

Answers (1)

Matteo Piombo
Matteo Piombo

Reputation: 6726

It appears that you instantiate a UIiAd as a property of your app delegate, and another UIiAd as a property of your viewController. Then:

UIiAd.delegate = self // The viewController's instance gets the delegate assigned
UIiAd = self.appdelegate().UIiAd // The viewController's instance changes and becomes the same as the app delegate's instance

This is not the way I'm used to deal with iAd, but in your case it might suffice changing the order of two lines of code:

UIiAd = self.appdelegate().UIiAd
UIiAd.delegate = self

Hope this helps

Upvotes: 2

Related Questions