【问题标题】:iAd's with Swift in SpriteKit在 SpriteKit 中使用 Swift 的 iAd
【发布时间】:2014-10-17 04:54:05
【问题描述】:

我正在开发一个应用程序并希望包含 iAd。我设法添加了横幅广告,并且效果很好。但是我想要一个更大的添加来填充大部分屏幕但不是全屏。我使用Benzene's Question and given solution from erdekhayser.中的代码添加了广告横幅

Apple iAd Documentation (Page 3)

我上面引用的链接来自苹果文档,苹果将 iAd 称为 MREC 广告。这就是我想要的。我不知道如何创建和添加一个。我已经尝试调整广告横幅的大小,但仍然无法弄清楚。

任何帮助将不胜感激

这是我目前的代码:

import UIKit
import SpriteKit
import iAd
import Twitter

var adBannerView: ADBannerView!

class GameViewController: UIViewController, ADBannerViewDelegate {

var scene: GameScene!

func loadAds() {

    adBannerView = ADBannerView(frame: CGRectZero)
    adBannerView.delegate = self
    adBannerView.hidden = true
    view.addSubview(adBannerView)
}

override func viewDidLoad() {
    super.viewDidLoad()

        // Configure the view.
        let skView = view as SKView
        skView.showsFPS = false
        skView.showsNodeCount = true
        skView.showsPhysics = false

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

        /* Set the scale mode to scale to fit the window */
        scene = GameScene(size: skView.bounds.size)
        scene.scaleMode = .AspectFill

        skView.presentScene(scene)

        //iAd
        loadAds()



}

//iAd
func bannerViewWillLoadAd(banner: ADBannerView!) {


    println("Ad about to load")

}

func bannerViewDidLoadAd(banner: ADBannerView!) {

    adBannerView.center = CGPoint(x: adBannerView.center.x, y: view.bounds.size.height - view.bounds.size.height + adBannerView.frame.size.height / 2)

    adBannerView.hidden = false
    println("Displaying the Ad")

}

func bannerViewActionDidFinish(banner: ADBannerView!) {


    println("Close the Ad")

}

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

    //pause game here


    println("Leave the application to the Ad")
    return true 
}

func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {

    //move off bounds when add didnt load

    adBannerView.center = CGPoint(x: adBannerView.center.x, y: view.bounds.size.height + view.bounds.size.height)

    println("Ad is not available")

}

【问题讨论】:

  • 请告诉我们您目前拥有的代码
  • 已经添加了我到目前为止的代码。希望你能帮忙
  • 你有没有得到任何地方?
  • 是的,我切换到谷歌广告。在我看来好多了
  • 嗯,好的。将 GoogleAdSense 放到您的应用中是否更容易?他们付的钱更好吗?

标签: ios swift sprite-kit xcode6 iad


【解决方案1】:

canDisplayBannerAds 设置为真。

override func viewDidLoad() {
super.viewDidLoad()

    // Configure the view.
    let skView = self.originalContentView as! SKView

    loadAds()

    self.canDisplayBannerAds = true // <--

    skView.showsFPS = false
    skView.showsNodeCount = true
    skView.showsPhysics = false

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

    /* Set the scale mode to scale to fit the window */
    scene = GameScene(size: skView.bounds.size)
    scene.scaleMode = .AspectFill

    skView.presentScene(scene)

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多