简体   繁体   中英

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()

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()

Let me see if i got your problem correctly, you want to hide your banner as soon as the purchase is made.

First, you need to set the bannerView as a property of your viewController.

Then you have to add this code inside the callback from the purchase success:
viewController.bannerView.removeFromSuperview();

I fixed it! Thanks for your help. I had to move the code from the GameViewController to the GameScene for the bannerAd so that I could remove it as soon as the purchase was made. Works perfectly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM