iAd没有显示任何广告,Swift,ViewController

时间:2015-04-22 00:19:14

标签: ios swift uiviewcontroller iad

当我运行游戏时,游戏顶部会出现一个白色方框,我猜这些广告会出现在那里,但是没有广告出现过!

我做错了什么,在某个地方丢失了某段代码,或者是盲目的?哈哈。

我对这个iAd和所有内容都很陌生!

以下是Click here For Image

的图片

这是ViewController代码!

import UIKit
import SpriteKit
import iAd


class GameViewController: UIViewController, ADBannerViewDelegate{

@IBOutlet var Banner: ADBannerView!

override func viewDidLoad() {
    super.viewDidLoad()

    if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
        // Configure the view.
        let skView = self.view as SKView
        skView.ignoresSiblingOrder = true

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

        skView.presentScene(scene)

        loadAds()
    }
}

func loadAds() {
    self.canDisplayBannerAds = true
    Banner = ADBannerView(frame: CGRect.zeroRect)
    Banner.center = CGPointMake(Banner.center.x, view.bounds.size.height - Banner.frame.size.height / 2)
    Banner.delegate = self
    Banner.hidden = true
    view.addSubview(Banner)
}


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

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

func bannerViewWillLoadAd(banner: ADBannerView!) {

}

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

func bannerViewDidLoadAd(banner: ADBannerView!) {
    self.Banner.hidden = false
}

2 个答案:

答案 0 :(得分:0)

它似乎突然起作用了!收到错误消息,但它已经消失,广告实际上已加载! :)

不知道发生了什么事!

答案 1 :(得分:0)

您的问题是除了以编程方式创建self.canDisplayBannerAds = true之外,您还在使用ADBannerView。从loadAds函数中删除self.canDisplayBannerAds = true