Swift SpriteKit:iAd加载bug

时间:2016-03-02 23:13:30

标签: ios swift sprite-kit iad

我目前正在处理我正在处理的应用程序的错误,当用户点击iAd横幅并加载广告时,游戏会重置。通过"重置"我的意思是他们所有的进展(除了NSUserDefaults数据)都被重置为0并且场景被重置回游戏的开始。

我的游戏主要来自 didMoveToView() touchesBegan()。在我的 GameViewController 中,游戏场景是从 viewWillLayoutSubviews()构建的。

以下是我控制广告和展示位置的方式。不确定是否与我的代码或广告的展示位置有关。

import UIKit
import SpriteKit
import iAd

// Global Ad Variable
var adBanner: ADBannerView!

class GameViewController: UIViewController, ADBannerViewDelegate {

/* Load Ads */
func loadAds() {
    adBanner = ADBannerView(frame: CGRect(x: 0, y: view.bounds.size.height - 50, width: 320, height: 50))
    adBanner.delegate = self
    adBanner.hidden = true
    self.view.addSubview(adBanner)
}

override func viewWillLayoutSubviews() {

    super.viewWillLayoutSubviews()

    if let scene = GameScene(fileNamed:"GameScene") {
        // Configure the view.
        let skView = self.view as! SKView

        // Create and Configure the scene
        scene.size = skView.bounds.size

        skView.showsFPS = false // SHOW OR HIDE FRAMES PER SECOND
        skView.showsNodeCount = false

        /* Sprite Kit applies additional optimizations to improve rendering performance */
        skView.ignoresSiblingOrder = true

        /* Set the scale mode to scale to fit the window */
        scene.scaleMode = .AspectFill

        skView.presentScene(scene)
    }

}

override func awakeFromNib() {
    super.awakeFromNib()
    loadAds()
}

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

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

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

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

func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
    adBanner.hidden = true
    print("There was an error loading ad")
}

func bannerViewWillLoadAd(banner: ADBannerView!) {
    print("Ad Loading")
}

func bannerViewDidLoadAd(banner: ADBannerView!) {
    adBanner.hidden = false
    print("Ad Loaded")
}
}

0 个答案:

没有答案