在 SpriteKit 中使用 Swift 的 iAd [英] iAd's with Swift in SpriteKit

查看:22
本文介绍了在 SpriteKit 中使用 Swift 的 iAd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am working on an app and would like to include iAd's. I have managed to add banner ad's and they work well. However i want to a larger add that fills most of the screen but not full screen. I added the adBanner using code from Benzene's Question and given solution from erdekhayser.

Apple iAd 文档(第 3 页)

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

The link i have referenced above is from the apple documentation and apple refer to the iAd as an MREC ad. This is what i would like to have. I cannot work out how to create and add one though. I have tried resizing the adBanner but still cannot figure it out.

任何帮助将不胜感激

这是我目前的代码:

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")

}

推荐答案

canDisplayBannerAds 设置为 true.

Set canDisplayBannerAds to true.

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)

}

这篇关于在 SpriteKit 中使用 Swift 的 iAd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆