在Swift中进行应用内购买后,广告不会被删除

时间:2015-08-18 20:29:05

标签: ios iphone xcode swift ipad

我制作了一个只提供一次应用程序内购买的应用程序来删除广告&等

我拥有在测试时进行应用内购买所需的所有代码 - 等等工作(例如:应用中的新模式),但广告不会被删除。

这就是我的尝试:

if defaults.boolForKey("removeAds") == true {


        canDisplayBannerAds = false
        adBannerView?.delegate = self
        adBannerView?.hidden = true
        adBannerView!.removeFromSuperview()

1 个答案:

答案 0 :(得分:1)

很难说出围绕您的实现的这么少的信息是什么问题,但要验证的一件事是您正在运行影响主线程上的UI的任何代码。

例如,您可以尝试使用dispatch_async块围绕该UI修改代码块:

if defaults.boolForKey("removeAds") == true {
    dispatch_async(dispatch_get_main_queue(), {
        self.canDisplayBannerAds = false
        self.adBannerView?.delegate = self
        self.adBannerView?.hidden = true
        self.adBannerView!.removeFromSuperview()
    }
}

另请注意,在dispatch_async区块内,您需要使用self来引用您的属性,以避免歧义。