我为AppStore开发了一个SpriteKit游戏,我将iAd添加到App中,但是当我运行App时,iAd有时会关闭并再次打开。对于AppStore的提交是否正确,或者我是否必须更改代码中的内容。
var UIiAd: ADBannerView = ADBannerView()
var SH = UIScreen.mainScreen().bounds.height
var BV: CGFloat = 0
override func viewDidLoad() {
super.viewDidLoad()
if let scene = GameScene(fileNamed:"GameScene") {
// Configure the view.
let skView = self.view as! SKView
skView.showsFPS = true
skView.showsNodeCount = true
/* 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)
}
}
// 1
func appdelegate() -> AppDelegate {
return UIApplication.sharedApplication().delegate as! AppDelegate
}
// 2
override func viewWillAppear(animated: Bool) {
print("Showing ad")
BV = UIiAd.bounds.height
UIiAd.delegate = self
UIiAd = self.appdelegate().UIiAd
UIiAd.frame = CGRectMake(0, SH - BV, 0, 0)
self.view.addSubview(UIiAd)
self.view.addSubview(UIiAd)
}
override func viewWillDisappear(animated: Bool) {
UIiAd.delegate = nil
UIiAd.removeFromSuperview()
}
// 4
func bannerViewDidLoadAd(banner: ADBannerView!) {
print("ad loaded")
UIiAd.frame = CGRectMake(0, SH + 50, 0, 0)
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(1)
UIiAd.alpha = 1
UIiAd.frame = CGRectMake(0, SH - 50, 0, 0)
UIView.commitAnimations()
}
// 5
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
print("failed to receive ad")
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(0)
UIiAd.alpha = 1
UIView.commitAnimations()
}
答案 0 :(得分:0)
没关系。根据(新)广告的可用性,iAd将隐藏横幅视图。