Zac
Zac

Reputation: 423

Programmatically add AdMob banner

Is there a way to implement adMob banners programmatically so that I can remove them with an in-app purchase (IAP)?

Something like the iAd:

self.canDisplayBannerAds = true

When there is that line of code the ads are displayed, else the space is used for other views, like a uitableview.

Upvotes: 1

Views: 647

Answers (2)

Coder1000
Coder1000

Reputation: 4461

The following is what I used for my IAP, and it works like a charm. It's executed once the IAP is bought.

func removeAds(){
    banner.removeFromSuperview()
    bannerGoogle.removeFromSuperview()
    outRemoveAds.removeFromSuperview()
    restorePurchases.removeFromSuperview()
    let theValue = 10
    NSUserDefaults.standardUserDefaults().setObject(theValue, forKey: "val")
    NSUserDefaults.standardUserDefaults().synchronize()
}

Just create IBOutlets for your ads.

Upvotes: 1

Memon Irshad
Memon Irshad

Reputation: 972

Use the following library. It makes it easy to implement and remove banner ads.

https://github.com/chrisjp/CJPAdController

Upvotes: 1

Related Questions