如何隐藏iAd横幅

时间:2015-08-20 00:03:47

标签: ios swift iad

我正在尝试在游戏中添加无广告选项。到目前为止,我已经通过在plist中保存bool来重新启动游戏时成功禁用了iAd。但是,在播放时摆脱当前广告无效。

我试过更改bannerView?变量隐藏,但即使屏幕上显示广告,它也会显示为零。

class GameViewController: UIViewController, ADBannerViewDelegate {

var bannerView:ADBannerView?

override func viewDidLoad() {
    super.viewDidLoad()

    if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {

        let skView = self.view as! SKView
        skView.showsFPS = false
        skView.showsNodeCount = false
        skView.ignoresSiblingOrder = true
        scene.scaleMode = .AspectFill

        NSNotificationCenter.defaultCenter().addObserver(self, selector: "updateNoAds:", name: "noAdsID", object: nil)

        skView.presentScene(scene)

    }

    if bannerAdsOff != true {

        self.canDisplayBannerAds = true

    } else {

        self.canDisplayBannerAds = false

    }


    let skView = self.originalContentView as! SKView
    self.bannerView?.delegate = self
    self.bannerView?.hidden = true

}

func updateNoAds(notification: NSNotification) {

    self.canDisplayBannerAds = false
    self.bannerView!.hidden = true

}

override func shouldAutorotate() -> Bool {
    return true
}

override func supportedInterfaceOrientations() -> Int {
    if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
        return Int(UIInterfaceOrientationMask.AllButUpsideDown.rawValue)
    } else {
        return Int(UIInterfaceOrientationMask.All.rawValue)
    }
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Release any cached data, images, etc that aren't in use.
}

override func prefersStatusBarHidden() -> Bool {
    return true
}

func bannerViewDidLoadAd(banner: ADBannerView!) {

        self.bannerView?.hidden = false
}

func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool  {
return willLeave
}

func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
    self.bannerView?.hidden = true
}


}

如果有人可以请指出我如何影响当前广告,或者如果有更好的方式让我停用广告,我会非常感激。感谢

0 个答案:

没有答案