AaoIi
AaoIi

Reputation: 8396

Placing iAd and Admob banner is causing an issue

I've been trying to do the following with iAd and Admob banner:

First i placed iAd over Admob banner in storyboard and I've added all the needed constraints, if iAd fail to receive i will show Admob banner if i received iAd i am gonna hide Admob and then show iAd banner..etc.

The issue doesn't happen all the time, while admob banner is showing iAd comes and push the admob banner to the top without hiding it. but in the code it should hide it.this issue happens after hiding and showing, hiding and showing many times..

Please check the following screenshot.

enter image description here

ViewController code:

@IBOutlet weak var Gbanner: GADBannerView!
@IBOutlet weak var AbannerView: ADBannerView!
override func viewDidLoad() {
    super.viewDidLoad()
    AbannerView.delegate = self
    self.canDisplayBannerAds = true
    showadmob()
    // Do any additional setup after loading the view, typically from a nib.


}


func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
    println("didFailToReceiveAdWithError")
    AbannerView.hidden = true
    Gbanner.hidden = false
}

func bannerViewActionDidFinish(banner: ADBannerView!) {
    println("bannerViewActionDidFinish")

}

func bannerViewDidLoadAd(banner: ADBannerView!) {
    println("bannerViewDidLoadAd")
    Gbanner.hidden = true
    AbannerView.hidden = false

}

func bannerViewWillLoadAd(banner: ADBannerView!) {

    println("bannerViewWillLoadAd")

}


func showadmob(){

self.Gbanner.adUnitID = "somethingelsehere"
self.Gbanner.rootViewController = self
var request: GADRequest = GADRequest()
self.Gbanner.loadRequest(request)

}

Download project here : https://yadi.sk/d/1VcjfJG9ixNZg

Upvotes: 1

Views: 109

Answers (1)

Daniel Storm
Daniel Storm

Reputation: 18878

If you're implementing your own ADBannerView then you need to remove self.canDisplayBannerAds = true from your viewDidLoad.

self.canDisplayBannerAds = true can be used for a no hassle way of implementing iAd banners in your application. This will create an ADBannerView for you and show or hide the ADBannerView depending on whether it receives an ad or not from the iAd network.

You either implement your own ADBannerView or use self.canDisplayBannerAds = true, not both.

Upvotes: 1

Related Questions