Search code examples
iosswiftadsrevmobrevmobads

Removing RevMob Ad banner upon in-App purchase


The problem is that Apple rejects my app because when the button is clicked to purchase the "no ads" upgrade, it doesn't make the banner disappear until you close the app and re-open it. This is because I initialize all my RevMob code in the viewController.swift file. I have a boolean in place that turns to false as soon as the upgrade is purchase inside this viewController.swift file. So next time you open the app and the viewController loads, the boolean is set to false and it doesn't allow the ads to appear.

Anybody know if this is the wrong way to go about this? Or is there an easy way to make them disappear immediately upon press of the no Ads button without having to close the app and re-open it?

//BANNER AD =======================================
let bannerBlock: () -> Void = {
    //Custom method defined below
    if UserDefaults.standard.object(forKey: "adsBool") as! Bool == true
    {
        self.showBannerWithCustomFrame()
    }
        else
    {
        //don't show ads because user purchased
    }
}
let bannerFailBlock: ((Error?) -> Void) = {error in
    NSLog("[RevMob Sample App] Session failed to start with error: \(error!.localizedDescription)")
}
RevMobAds.startSession(withAppID: "00000000000000000000",
    withSuccessHandler: bannerBlock,
    andFailHandler: bannerFailBlock)

This is how my bannerView is set up in my GameViewController

class GameViewController: UIViewController, RevMobAdsDelegate {
    var bannerView:RevMobBannerView?

    override func viewDidLoad() {
    super.viewDidLoad()

Solution

  • From RevMob's banner documentation, there's a method called hideAd. Calling that method on the IAP callback would solve your problem right?

    To hide the banner: banner!.hideAd()