在SceneKit视图上实现iAd

时间:2014-12-30 23:40:07

标签: ios xcode swift iad scenekit

尝试实施iAd横幅时出现问题。不确定我错过了什么。我的主要故事板是为scenekit显示设置的。我试图同时在屏幕上显示广告。我在setupAds func中手动创建和添加视图,如下所示。我还在下面添加了代理例程,它们正在触发,但我没有看到广告显示。

let adBannerView = ADBannerView(frame: CGRect.zeroRect)

override func viewDidLoad() {

    super.viewDidLoad()
    /* My other setup code here */

    setupAds()
}

func setupAds() {
    adBannerView.center = CGPoint(x: adBannerView.center.x, y: view.bounds.size.height - adBannerView.frame.size.height / 2)
    adBannerView.delegate = self
    adBannerView.hidden = true
    view.addSubview(adBannerView)
}

/* My funcs to handle the splash screen and game */

// iAd delegates

func bannerViewWillLoadAd(banner: ADBannerView!) {
    println("bannerViewWillLoadAd")
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
    self.adBannerView.alpha = 1.0
    println("bannerViewDidLoadAd")
}
func bannerViewActionDidFinish(banner: ADBannerView!) {
    println("bannerViewActionDidFinish")
}
func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
    println("bannerViewActionShouldBegin")
    return true 
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
    println("bannerViewError")
    println(error)

}

我得到的输出如下。

bannerViewWillLoadAd
bannerViewDidLoadAd
bannerViewError
Error Domain=ADErrorDomain Code=1 "Service session terminated." UserInfo=0x17466a6c0 {ADInternalErrorCode=1002, NSLocalizedDescription=Service session terminated.}

知道我在这里失踪的是什么吗?

非常感谢提前。

1 个答案:

答案 0 :(得分:1)

好的Indrajeet是对的。需要被添加到超级而不是自我。代码现在看起来像:

覆盖func viewDidLoad(){

    super.viewDidLoad()
    super.view.addSubview(adBannerView) // This is where I needed to add the banner.

    /* Other setup stuff here */

    setupAds()
}

func setupAds() {
    adBannerView.center = CGPoint(x: adBannerView.center.x, y: view.bounds.size.height - adBannerView.frame.size.height / 2)
    adBannerView.center = CGPoint(x: view.bounds.size.width / 2, y: view.bounds.size.height - adBannerView.frame.size.height / 2)
    adBannerView.delegate = self
    adBannerView.hidden = true
}

  // iAd delegates
func bannerViewWillLoadAd(banner: ADBannerView!) {
    println("bannerViewWillLoadAd")
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
    banner.hidden = false
    println("bannerViewDidLoadAd")
}
func bannerViewActionDidFinish(banner: ADBannerView!) {
    println("bannerViewActionDidFinish")
}
func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
    println("bannerViewActionShouldBegin")
    return true 
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
    println("bannerViewError")
    println(error)
}

这基本上允许我在场景包显示之上添加标准的iAd视图。今天广告 - 明天,世界!