Uninstall all iAds apps?

I added in-app purchases to uninstall iAds for my iOS app.

I put this in the logic after purchasing the removeAds product (which definitely runs):

func removeAds() {
    defaults.setObject("True", forKey: "remove_adverts")
    self.canDisplayBannerAds = false
    self.removeAdButton.enabled = false
    println("removed")
}

      

And I put this at the top of each controller to handle it.

if let showAds = defaults.dataForKey("remove_adverts") {
    self.canDisplayBannerAds = false
    self.removeAdButton.enabled = false
    println("Ads shouldn't show")
} else {
    self.canDisplayBannerAds = true
}

      

But ad impressions are showing.

Is there a better way to do this?

+3


source to share


1 answer


When you check if a user has purchased IAP to remove ads on this line if let showAds = defaults.dataForKey("remove_adverts")

, you check dataForKey

when you should check objectForKey

because you used setObject

when setting the value default

. Alternatively, you can use setBool

to make your code look something like this:

func removeAds() {
    defaults.setBool(true, forKey: "removeAdsPurchased")
    self.canDisplayBannerAds = false
    println("iAd removed and default value set")
    defaults.synchronize()
}

      



and

    let showAds = defaults.boolForKey("removeAdsPurchased")
    if (showAds) {
        // User purchsed IAP
        // Lets remove ads
        self.canDisplayBannerAds = false
        println("iAd removed")
    } else {
        // IAP not purchased
        // Lets show some ads
        self.canDisplayBannerAds = true
        println("Showing iAd")
    }

      

+1


source







All Articles