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)
}
}
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!
}
}